Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to query a GraphQL API for a user's name.
GraphQL
query { user(id: [1]) { name } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted numbers for string IDs
Using single quotes instead of double quotes
✗ Incorrect
The user ID must be a string in quotes in GraphQL queries.
2fill in blank
mediumComplete the code to handle errors in a GraphQL response.
GraphQL
if (response.[1]) { console.error(response.errors); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'data' instead of 'errors'
Checking HTTP status codes only
✗ Incorrect
GraphQL responses include an 'errors' field when errors occur.
3fill in blank
hardFix the error in the GraphQL query to fetch a user's email.
GraphQL
query { user(id: [1]) { email } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted numbers
Using single quotes instead of double quotes
✗ Incorrect
The ID must be a string in double quotes for the query to work correctly.
4fill in blank
hardFill both blanks to check if a GraphQL response has errors and log them.
GraphQL
if (response.[1] && response.[2].length > 0) { console.log('Errors found'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'data' or 'status' instead of 'errors'
✗ Incorrect
GraphQL errors are in the 'errors' array; check if it exists and has items.
5fill in blank
hardFill all three blanks to extract data, check errors, and handle them in GraphQL response.
GraphQL
const [1] = response.[2]; if (response.[3]) { console.error('GraphQL errors:', response.errors); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'status' instead of 'errors'
Not extracting 'data' properly
✗ Incorrect
Extract 'data' from response, check 'errors' field to handle errors.