When passing arguments to a GraphQL mutation, you can send them inline, or you can wrap them in an input type. In this lesson, we’ll create an input type for the addDay mutation which will allow us to pass an entire object as an argument.
Instructor: [00:00] First let's organize our arguments into an input type. Then I can highlight and delete all of the arguments sent to addDay and instead pass in the input addDayInput and we'll make it non-nullable. Now in the resolver all of these givens are going to listed under the input key. Here I can destructure date, mountain, and conditions.
[00:28] Now over in the playground, I'm going to create my mutation. I'll create a variable for input and set that to our addDayInput. I'm going to pass in input as an argument, and set that to the value of the variable. I'll request date, mountain, and conditions as the mutation response, and in the query variables panel I'm going to send these arguments under the input key. So the input object will have a field for date, for mountain, and for conditions.
[01:03] Now once I run this, we're going to see the addDay mutation execute as expected. Again, the input type is a wrapper around a set of arguments. We send that to the addDay mutation, and then we're going to destructure those values from under the input key because we're sending an entire input object each time we send the mutation.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!