10. Mutations
5m

(Text covers the exact same content as the video)

Lesson tasks

Practice

POST requests are usually accompanied by a payload. How do we send that payload to the REST API endpoint using a Connector?

Use the following schema to answer the next few questions.

type Mutation {
createPlanet(input: CreatePlanetInput!): Planet
@connect(
source: "outerspace"
http: {
POST: "/planets"
body: """
???
"""
}
selection: """
id
name
mass
"""
)
}
type CreatePlanetInput {
"The planet's name"
name: String!
"The total estimated mass of the planet (in kg)"
mass: Int
}
"Astronomical information for a single planet."
type Planet {
"The ID for the planet"
id: ID!
"The planet's name"
name: String!
"The total estimated mass of the planet (in kg)"
mass: Int
}

Below is an example of a JSON payload for the request body of the POST /planets endpoint.

POST request's body payload
{
"name": "Mraza",
"mass": 6.42
}
Which of the following mappings for the body parameter should replace the ??? placeholder in the schema?

Key takeaways

  • We can apply Connectors to Mutation type just as we do for Query type .
  • When submitting data to a POST endpoint, we can include a body in our Connector's http definition.

Conclusion

Well done! You've successfully built an API powered by . You now have the tools and patterns to keep on exploring and building.

Let us know about what you're creating, and what you'd like to see next. Drop us a note in the community forum.

Want to keep learning? Dive deeper into the syntax with Expressions in Connectors: Mapping and Transforms.

See you next time!


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.