This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Dynamically Update Local State using Apollo Link State with Mutation Variables

    Ben AwadBen Awad

    In this lesson, you will learn how to use variables to update local state in React with your Apollo Link State Mutations.

    reactReact
    apolloApollo
    graphqlGraphQL
    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:01 To add a variable to our mutation, we need to start by updating our GQL. I'm going to add parentheses and then give the variable a name. I'm going to call it amount. Then we have to specify the data type, which is int. It's required.

    00:15 I can pass the amount into the mutation. I'm going to say amount is equal to my variable called amount. This amount, I need to pass in when I call the increment mutation. We're calling it right here.

    00:27 I'm going to say onclick. We're going to call increment. I need to pass in variables. The variable I need to pass in is this amount. I'm going to say amount is equal to two.

    00:40 I can use this amount in my mutation up here. It's going to be the second parameter. I called it amount. Now I can use that in the actual data that I write.

    00:52 When I save this, I can click the plus. We're incrementing by two. I can change this to anything I want to. Let's do four. Now we increment by four.

    Discuss

    Discuss