Given the following GraphQL query and variables, what will be the value of user.name in the response?
query GetUser($id: ID!) {
user(id: $id) {
name
}
}Variables:
{"id": "42"}Assume the user with ID "42" has the name "Alice".
query GetUser($id: ID!) {
user(id: $id) {
name
}
}Variables replace the placeholders in the query. The user with ID "42" is named "Alice".
The variable $id is set to "42", so the query fetches the user with ID "42". The response returns the user's name "Alice".
Choose the correct syntax to declare a required variable $limit of type Int in a GraphQL query.
Required variables use an exclamation mark ! after the type and must be declared with a $ prefix.
Option A correctly declares $limit as a required Int variable. Option A is optional (no !). Option A misses a colon. Option A misses the $ before limit.
Which of the following best explains how using query variables can improve performance in GraphQL?
Think about how the server handles queries with the same structure but different inputs.
Using variables lets the server parse and validate the query once, then reuse the execution plan with different variable values. This saves processing time and improves performance.
Given this query:
query GetPost($postId: ID!) {
post(id: $postId) {
title
}
}If the request is sent without providing postId in variables, what error will the server return?
Required variables must be provided or the server returns an error.
The server returns an error message indicating the required variable $postId was not provided, as it is mandatory.
Which of the following is the best reason to use query variables rather than hardcoding values directly in GraphQL queries?
Think about how variables help with query reuse and server caching.
Using variables lets clients send the same query text with different inputs, which helps caching and makes code easier to maintain. The other options are incorrect or unrelated.