5. Codealong - Configure HTTP Callback
10m

Overview

To set up via HTTP callback in our , we need to modify our router-config.yaml file that sets our '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.

router/router-config.yaml
# ... other configuration
subscription:
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: true
mode:
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 's public URL that must be able to send new data to. By default, a locally running router runs on http://127.0.0.1:4000, and we've appended /callback as the specific endpoint the should use when "calling back" to the .

  • The listen property specifies the IP address and port the will listen on for 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 's callback endpoint. It should match the value appended to the public_url. If you don't specify a path here, it takes the value of /callback by default.

subscription:
enabled: true
mode:
callback:
public_url: http://127.0.0.1:4000/callback
listen: 127.0.0.1:4000
path: /callback

Finally, we can add the last two properties. heartbeat_interval specifies the interval at which the should "check in" with the to make sure communication is still possible. This property is optional, but we'll include it as 5s. Lastly we specify which implement this protocol.

The complete callback implementation
subscription:
enabled: true
mode:
callback:
public_url: http://127.0.0.1:4000/callback
listen: 127.0.0.1:4000
path: /callback
heartbeat_interval: 5s
subgraphs:
- messages

With these settings in place, let's restart our so it can pick them up. (Swap in your 's unique APOLLO_GRAPH_REF and APOLLO_KEY.)

APOLLO_KEY=somethingsomethingsomething \
APOLLO_GRAPH_REF=mygraphname@current \
./router \
--config ./router-config.yaml
Previous

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.