Overview
To set up subscriptions via HTTP callback in our graph, we need to modify our router-config.yaml
file that sets our router's settings. Let's jump in there now.
This starts with a top-level property called subscription
, and right away we set an enabled
property to true
.
# ... other configurationsubscription:enabled: true
Next, we specify the mode
. Our mode is callback
, which we'll place on a new line so we can specify additional properties.
subscription:enabled: truemode:callback:
Now under callback
we need to set a number of properties.
public_url
listen
path
heartbeat_interval
subgraphs
Let's start with those first three properties, because they're related:
The
public_url
property represents the router's public URL that subgraphs must be able to send new subscription data to. By default, a locally running router runs onhttp://127.0.0.1:4000
, and we've appended/callback
as the specific endpoint the subgraphs should use when "calling back" to the router.The
listen
property specifies the IP address and port the router will listen on for subscription callbacks. We haven't changed it from the default value here; but note that for security reasons, it's best to expose a separate port that's available only through your internal network.The
path
property states the specific path of our router's callback endpoint. It should match the value appended to thepublic_url
. If you don't specify apath
here, it takes the value of/callback
by default.
subscription:enabled: truemode:callback:public_url: http://127.0.0.1:4000/callbacklisten: 127.0.0.1:4000path: /callback
Finally, we can add the last two properties. heartbeat_interval
specifies the interval at which the subgraph should "check in" with the router to make sure communication is still possible. This property is optional, but we'll include it as 5s
. Lastly we specify which subgraphs implement this protocol.
subscription:enabled: truemode:callback:public_url: http://127.0.0.1:4000/callbacklisten: 127.0.0.1:4000path: /callbackheartbeat_interval: 5ssubgraphs:- messages
With these settings in place, let's restart our router so it can pick them up. (Swap in your graph's unique APOLLO_GRAPH_REF
and APOLLO_KEY
.)
APOLLO_KEY=somethingsomethingsomething \APOLLO_GRAPH_REF=mygraphname@current \./router \--config ./router-config.yaml
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.