0
0
GraphQLquery~10 mins

Why resolvers connect schema to data in GraphQL - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a resolver that returns a user's name.

GraphQL
const resolvers = { Query: { user: () => [1] } };
Drag options to blanks, or click blank then click option'
Aname
B'Alice'
C{ name: 'Alice' }
Duser.name
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a string instead of an object.
Using undefined variables.
2fill in blank
medium

Complete the resolver to fetch a list of books from data.

GraphQL
const resolvers = { Query: { books: () => [1] } };
Drag options to blanks, or click blank then click option'
AbookData
BgetBooks()
CfetchBooks
DbooksList
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that is not defined.
Returning a function reference instead of data.
3fill in blank
hard

Fix the error in the resolver to correctly return the user's email.

GraphQL
const resolvers = { User: { email: (parent) => [1] } };
Drag options to blanks, or click blank then click option'
Aparent.email
Bparent.getEmail()
Cemail
Dparent.emailAddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong property name.
Calling a method that does not exist.
4fill in blank
hard

Fill both blanks to define a resolver that fetches a post by ID from data.

GraphQL
const resolvers = { Query: { post: (_, args) => [1].find(p => p.[2] === args.id) } };
Drag options to blanks, or click blank then click option'
Aposts
BpostList
Cid
DpostId
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable or property names.
Mixing up argument and property names.
5fill in blank
hard

Fill all three blanks to create a resolver that returns the titles of all books published after a given year.

GraphQL
const resolvers = { Query: { recentBooks: (_, args) => [1].filter(book => book.[2] > args.[3]).map(book => book.title) } };
Drag options to blanks, or click blank then click option'
Abooks
BpublishedYear
Cyear
DpublishDate
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property or argument names.
Not chaining filter and map correctly.