Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

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

Autoplay

    Wrap GraphQL Mutation Arguments with a GraphQL Input Type

    Eve PorcelloEve Porcello
    apolloApollo
    graphqlGraphQL

    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.

    Code

    Code

    Become a Member to view code

    You must be a 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
    Transcript

    Transcript

    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.

    Discuss

    Discuss