0
0
GraphQLquery~10 mins

Default resolvers in GraphQL - Interactive Code Practice

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

Complete the code to define a simple GraphQL query that returns a string.

GraphQL
type Query { greeting: [1] }
Drag options to blanks, or click blank then click option'
ABoolean
BInt
CString
DFloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int or Boolean when the field should return text.
Forgetting to specify the type after the field name.
2fill in blank
medium

Complete the resolver function to return the greeting string.

GraphQL
const resolvers = { Query: { greeting: () => [1] } };
Drag options to blanks, or click blank then click option'
Aconsole.log('Hello, world!')
B'Hello, world!'
Creturn 'Hello, world!'
DHello, world!
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the string.
Using console.log instead of returning a value.
3fill in blank
hard

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

GraphQL
const resolvers = { Query: { userName: (parent, args, context, info) => [1] } };
Drag options to blanks, or click blank then click option'
Acontext.user.name
Bcontext.userName
Cargs.name
Dparent.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using args or parent instead of context for user info.
Using incorrect property names like userName instead of user.name.
4fill in blank
hard

Fill both blanks to define a resolver that returns a list of posts with titles.

GraphQL
const resolvers = { Query: { posts: () => [1].map(post => post.[2]) } };
Drag options to blanks, or click blank then click option'
ApostsData
Btitle
Ccontent
Dauthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property like content or author instead of title.
Using an undefined variable instead of postsData.
5fill in blank
hard

Fill all three blanks to create a resolver that filters users by age greater than 18 and returns their names.

GraphQL
const resolvers = { Query: { adultUserNames: () => users.filter(user => user.[1] [2] [3]).map(user => user.name) } };
Drag options to blanks, or click blank then click option'
Aage
B>
C18
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property like name instead of age in the filter.
Using incorrect comparison operators like < or ==.