1×
Become a member
to unlock all features

Save 40% this week only!

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

Autoplay

    Filter Data Based on Query Arguments with GraphQL

    Eve PorcelloEve Porcello
    graphqlGraphQL

    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.

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

    00:17 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.

    00:29 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.

    00:43 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.

    Discuss

    Discuss