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: """idnamemass""")}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.
{"name": "Mraza","mass": 6.42}
body
parameter should replace the ???
placeholder in the schema?Key takeaways
- We can apply Connectors to
Mutation
type fields just as we do forQuery
type fields. - When submitting data to a
POST
endpoint, we can include abody
in our Connector'shttp
definition.
Conclusion
Well done! You've successfully built an API powered by Apollo Connectors. 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 selection mapping 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.