Bird
0
0

You want to query a user by id and get their name and email. Which query correctly uses variables?

hard📝 Application Q9 of 15
GraphQL - Queries
You want to query a user by id and get their name and email. Which query correctly uses variables?
A{ user(id: $id) { name email } }
Bquery getUser(id) { user(id: id) { name email } }
Cquery { user(id: $id) { name email } }
Dquery getUser($id: ID!) { user(id: $id) { name email } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable declaration syntax

    Variables are declared with $ and type in parentheses after query name.
  2. Step 2: Check variable usage in query

    query getUser($id: ID!) { user(id: $id) { name email } } correctly declares $id as ID! and uses it in the user field argument.
  3. Final Answer:

    query getUser($id: ID!) { user(id: $id) { name email } } -> Option D
  4. Quick Check:

    Variables declared and used with $ and type = query getUser($id: ID!) { user(id: $id) { name email } } [OK]
Quick Trick: Declare variables with $ and type after query name [OK]
Common Mistakes:
  • Omitting variable type
  • Not using $ in variable usage
  • Missing variable declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes