Overview
With HTTP callbacks, a subgraph server uses a callback URL provided by the router to send new subscription data as soon as it becomes available. This process occurs without maintaining a long-lived, resource-intensive connection—instead, the subgraph "checks in" periodically with the router.
Process at a glance
There are three primary roles involved in this process: the router, the subgraph, and the emitter.
The router receives the query, and breaks it up to fetch data from each responsible subgraph. In addition, it tells the subgraph(s) that provide subscription data how to "call back" when new data is available.
The emitter is the mechanism that checks in with the router periodically and "emits" new subscription data. (This can be a separate service—or the subgraph itself.)
The subgraph's roles & responsibilities
- Receive subscription operation from router
- Establish connection with the router
- Retrieve and return data
- Manage periodic check-ins
The subgraph also needs to be running a framework that has implemented support for the HTTP Callback Protocol. This comes out of the box with Apollo Server.
Note: Because our subgraph server takes on the role of both subgraph and emitter, it's handling the last step, periodically checking in with the router.
The router's roles & responsibilities
- Receive operations from clients, break them up across the graph, and return the response
- Set the HTTP callback configuration:
- Define path and port
- How often the subgraph should check in
- Which subgraphs support subscriptions
Share your questions and comments about this lesson
Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.
You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.