Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Wrap GraphQL Mutation Arguments with a GraphQL Input Type


    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.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: 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.

    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.

    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.