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 fields like age or email which do not fetch the name.
Using id instead of name.
✗ Incorrect
The field name fetches the user's name as required.
2fill in blank
mediumComplete the code to add an argument to fetch a user by their username.
GraphQL
query GetUser { user([1]: "alice") { id name } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using id instead of username.
Using email or age which are not the correct arguments here.
✗ Incorrect
The argument username is used to fetch a user by their username.
3fill in blank
hardFix the error in the GraphQL query to correctly fetch a list of posts with their titles.
GraphQL
query { posts { [1] } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plural
titles which is not a valid field.Using
postTitle or name which do not exist.✗ Incorrect
The field title correctly fetches the title of each post.
4fill in blank
hardFill both blanks to create a mutation that adds a new user with a name and email.
GraphQL
mutation AddUser { addUser(name: [1], email: [2]) { id name email } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around string values.
Mixing up name and email values.
✗ Incorrect
The mutation requires string values for name and email. Using quotes is necessary.
5fill in blank
hardFill all three blanks to write a query that fetches a user's id, name, and their posts' titles.
GraphQL
query GetUserPosts { user(id: [1]) { [2] posts { [3] } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numeric id.
Using wrong field names for posts.
✗ Incorrect
The user is fetched by id 1, then name and title of posts are requested.