Bird
0
0

You want to fetch a list of users with their id, name, and each user's posts with post title and comments count. Which GraphQL query correctly expresses this?

hard📝 Application Q15 of 15
GraphQL - Queries
You want to fetch a list of users with their id, name, and each user's posts with post title and comments count. Which GraphQL query correctly expresses this?
Aquery { users { id name posts { title commentsCount, } } }
Bquery { users { id, name, posts { title, commentsCount } } }
Cquery { users { id name posts { title, commentsCount } } }
Dquery { users { id name posts { title commentsCount } } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested fields and syntax

    The query must request 'users' with subfields 'id', 'name', and nested 'posts' with 'title' and 'commentsCount'. In single-line GraphQL queries, commas are required to separate field names, and trailing commas are invalid.
  2. Step 2: Evaluate syntax correctness

    'query { users { id, name, posts { title, commentsCount } } }' correctly separates all fields with commas at every level without trailing commas. The others have errors: missing commas between some fields combined with trailing comma; missing commas between top-level fields; or missing all commas between fields.
  3. Final Answer:

    query { users { id, name, posts { title, commentsCount } } } -> Option B
  4. Quick Check:

    Correct nesting and commas between fields = query { users { id, name, posts { title, commentsCount } } } [OK]
Quick Trick: Nest fields inside braces without trailing commas [OK]
Common Mistakes:
  • Adding trailing commas inside nested fields
  • Misplacing commas between fields
  • Incorrect nesting of fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes