5. The @connect directive
5m

(Text covers the exact same content as the video)

Lesson tasks

Practice

Which of the following @connect directive parameters should you use to map the endpoint's specific JSON properties to your GraphQL schema?

Use the REST API JSON response below to complete the code challenge.

REST API JSON response
{
"id": "px-m012",
"name": "Mraza",
"mass": 6.42
}
HINT: @connect boilerplate code
@connect(
source: ""
http: { GET: "" }
selection: """
# TODO
"""
)
Code Challenge!

Add the @connect directive to the Query.popularPlanets field. Use the outerspace source and the API endpoint GET /planets?sort=popular. Refer to the JSON object above and the existing schema to define the selection.

Loading...
Loading progress

Key takeaways

  • The @connect describes how to get the data for a particular using a defined source.
  • Each root (the fields on the Query and Mutation types) requires a @connect .
  • We use @connect's http parameter to define the HTTP method and URL parameters on the source that should be used to retrieve data for a .
  • We use @connect's selection parameter to map the REST API's JSON response to our .

Up next

We started small with just a couple of , but there's more to show! Let's add more fields and see what happens when our mapping doesn't quite match one-to-one.

Next

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.