Which of the following is the correct syntax for a simple GraphQL query to get a user's name and email?
easy📝 Syntax Q12 of 15
GraphQL - Queries
Which of the following is the correct syntax for a simple GraphQL query to get a user's name and email?
Aquery { user { name, email } }
Bquery user { name, email }
C{ user: name, email }
Dquery { user: name, email }
Step-by-Step Solution
Solution:
Step 1: Identify correct GraphQL query structure
A GraphQL query starts with optional 'query' keyword, then curly braces containing the root field and requested subfields separated by commas or spaces.
Step 2: Check each option's syntax
'query { user { name, email } }' correctly uses the 'query' keyword, outer braces, nested 'user' braces for fields. 'query user { name, email }' misses opening brace after 'query'; '{ user: name, email }' lacks 'query' and uses invalid colon; 'query { user: name, email }' uses invalid colon after 'user'.