Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a GraphQL query that fetches a user's name.
GraphQL
query GetUserName { user(id: 1) { [1] } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a field that does not represent the user's name.
Using a field that does not exist in the schema.
✗ Incorrect
The field name correctly fetches the user's name as requested.
2fill in blank
mediumComplete the code to add a variable for user ID in the query.
GraphQL
query GetUser($id: ID!) { user(id: [1]) { name } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a literal value instead of the variable.
Using a variable name without the dollar sign.
✗ Incorrect
The variable $id is used to pass the user ID dynamically to the query.
3fill in blank
hardFix the error in the mutation to update a user's email.
GraphQL
mutation UpdateEmail($id: ID!, $email: String!) { updateUser(id: [1], email: $email) { id email } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the field name instead of the variable.
Omitting the dollar sign before the variable.
✗ Incorrect
The variable $id must be used to pass the user ID in the mutation arguments.
4fill in blank
hardFill both blanks to define a fragment for user details and use it in a query.
GraphQL
fragment UserDetails on User { [1] [2] } query GetUser { user(id: 1) { ...UserDetails } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including fields not present in the User type.
Using fields unrelated to user details.
✗ Incorrect
The fragment includes name and email fields to fetch user details.
5fill in blank
hardFill all three blanks to write a query with variables and aliasing.
GraphQL
query GetUserInfo($userId: ID!) { userInfo: user(id: [1]) { [2] email: [3] } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using literal values instead of variables.
Confusing alias and field names.
Omitting the dollar sign for variables.
✗ Incorrect
The query uses variable $userId for the ID, fetches name, and aliases emailAddress as email.