Bird
0
0

Which of the following is the correct syntax to declare a variable named $userId of type ID! in a GraphQL query?

easy📝 Syntax Q3 of 15
GraphQL - Queries
Which of the following is the correct syntax to declare a variable named $userId of type ID! in a GraphQL query?
Aquery getUser { user(id: $userId: ID!) { name } }
Bquery getUser($userId ID!) { user(id: $userId) { name } }
Cquery getUser($userId: ID!) { user(id: $userId) { name } }
Dquery getUser($userId: ID) { user(id: $userId!) { name } }
Step-by-Step Solution
Solution:
  1. Step 1: Review correct variable declaration syntax

    Variables are declared in parentheses after query name with format ($name: Type!).
  2. Step 2: Check each option for syntax correctness

    Only query getUser($userId: ID!) { user(id: $userId) { name } } follows the correct syntax with $userId: ID! inside parentheses.
  3. Final Answer:

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

    Variable declaration syntax = correct parentheses and colon [OK]
Quick Trick: Declare variables inside parentheses with colon and type [OK]
Common Mistakes:
  • Missing parentheses
  • Wrong colon placement
  • Incorrect exclamation mark usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes