0
0
GraphQLquery~5 mins

Query arguments in GraphQL

Choose your learning style9 modes available
Introduction

Query arguments let you ask for specific data by giving extra details.

When you want to get information about a single user by their ID.
When you need to filter a list of products by category.
When you want to limit the number of results returned.
When you want to sort data, like showing newest posts first.
Syntax
GraphQL
query {
  fieldName(argumentName: argumentValue) {
    subField
  }
}

Arguments go inside parentheses after the field name.

Argument values can be strings, numbers, booleans, or variables.

Examples
Get user details by ID "123".
GraphQL
query {
  user(id: "123") {
    name
    email
  }
}
Get products only in the "books" category.
GraphQL
query {
  products(category: "books") {
    title
    price
  }
}
Get only 5 posts.
GraphQL
query {
  posts(limit: 5) {
    title
    date
  }
}
Sample Program

This query asks for the name and age of the user with ID "1".

GraphQL
query {
  user(id: "1") {
    name
    age
  }
}
OutputSuccess
Important Notes

Arguments help make queries flexible and precise.

Always check the schema to know which arguments a field accepts.

Summary

Query arguments let you specify exactly what data you want.

They go inside parentheses after the field name.

Use them to filter, limit, or sort data in your queries.