Become a member
to unlock all features

Level Up!

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


    Filter Data Based on Query Arguments with GraphQL


    With GraphQL, every field and nested object can have a set of arguments which can be used to request very specific data from a GraphQL API. In this lesson, we will pass arguments to the GitHub API inline and as query variables.



    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: Let's create a query for user. The user query requires an argument of login, a user's GitHub login. Then we'll request name, company, followers. Nested under followers, we'll get the total count. Click "play" and you'll see the data returned in the same shape as the query.

    You can also send query arguments as variables. We'll start by creating the variable name on line one. We'll also designate the type, a required string, which must match the type in the schema.

    Now, replace the string with a variable. We send query arguments in the query variable's panel as JSON. Here, we'll provide a value for login. Click "play" and we should see the data for the new user.

    Login is a required string, but we can also set a default value with an equal sign. Now, if I remove the query variable's object and don't pass anything in, the query will still execute with a default login value.