Recall & Review
beginner
What are query variables in GraphQL?
Query variables are placeholders in a GraphQL query that allow you to pass dynamic values separately from the query text. They help make queries reusable and secure.
Click to reveal answer
beginner
How do you declare a variable in a GraphQL query?
You declare variables inside parentheses after the query name, using a dollar sign ($) followed by the variable name and its type, for example:
query GetUser($id: ID!).Click to reveal answer
intermediate
Why use query variables instead of hardcoding values in GraphQL queries?
Using variables keeps queries clean, reusable, and helps prevent injection attacks by separating data from query structure.
Click to reveal answer
beginner
How do you pass values to query variables when sending a GraphQL request?
You pass a separate JSON object with variable names and their values alongside the query. For example:
{ "id": "123" }.Click to reveal answer
intermediate
What does the exclamation mark (!) mean in a variable type like
$id: ID!?The exclamation mark means the variable is non-nullable, so you must provide a value for it when running the query.
Click to reveal answer
How do you indicate a variable in a GraphQL query?
✗ Incorrect
GraphQL variables are always indicated by a dollar sign ($) before the variable name.
Where do you declare variables in a GraphQL query?
✗ Incorrect
Variables are declared inside parentheses right after the query or mutation name.
What type of value does
ID! represent in a variable declaration?✗ Incorrect
The exclamation mark means the ID is non-nullable and must be provided.
How do you pass variable values when sending a GraphQL query?
✗ Incorrect
Variable values are passed as a separate JSON object, not inside the query string.
Why are query variables useful in GraphQL?
✗ Incorrect
Variables help keep queries reusable and prevent injection attacks by separating data from query structure.
Explain how to use query variables in a GraphQL query from declaration to passing values.
Think about the three steps: declare, use, and pass values.
You got /3 concepts.
Why is it better to use query variables instead of hardcoding values in GraphQL queries?
Consider reusability and security benefits.
You got /3 concepts.