Filter Data Based on Query Arguments with GraphQL

Eve Porcello
InstructorEve Porcello
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 4 years ago

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.

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.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today