Bird
0
0

Find the mistake in this GraphQL query:

medium📝 Debug Q6 of 15
GraphQL - Queries
Find the mistake in this GraphQL query:
query fetchProduct($productId: ID!) { product(id: productId) { name price } }
AThe variable type ID! should be ID without exclamation mark
BThe variable $productId is not referenced correctly inside the query
CThe query name fetchProduct is missing a required directive
DThe fields name and price cannot be queried together
Step-by-Step Solution
Solution:
  1. Step 1: Analyze variable usage

    The variable declared is $productId, but inside the query it is used as productId without the $ prefix.
  2. Step 2: Check other options

    The variable type ID! should be ID without exclamation mark is incorrect because ID! is a valid non-null type. The query name fetchProduct is missing a required directive and D are unrelated to variable usage.
  3. Final Answer:

    The variable $productId is not referenced correctly inside the query -> Option B
  4. Quick Check:

    Variables must be referenced with $ inside queries [OK]
Quick Trick: Always prefix variables with $ inside query fields [OK]
Common Mistakes:
  • Omitting $ when using variables in query arguments
  • Misunderstanding non-null type syntax
  • Assuming query names require directives

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes