0
0
GraphQLquery~10 mins

Why databases back 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 GraphQL query that fetches all users.

GraphQL
type Query { users: [1] }
Drag options to blanks, or click blank then click option'
A[User]
BUser
CString
DInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'User' instead of '[User]' which returns a single user, not a list.
Using scalar types like String or Int for a list of users.
2fill in blank
medium

Complete the resolver function to fetch users from the database.

GraphQL
const resolvers = { Query: { users: async () => await [1].find() } }
Drag options to blanks, or click blank then click option'
AGraphQL
BUserModel
Cdatabase
DfetchUsers
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'database' or 'GraphQL' which are not the model names.
Using a function name like 'fetchUsers' instead of the model.
3fill in blank
hard

Fix the error in the GraphQL schema to correctly define a user type with id and name.

GraphQL
type User { id: ID! name: [1]! }
Drag options to blanks, or click blank then click option'
AInt
BFloat
CBoolean
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int or Boolean for name which are incorrect types.
Using Float which is for decimal numbers.
4fill in blank
hard

Fill both blanks to write a resolver that fetches a user by id from the database.

GraphQL
const resolvers = { Query: { user: async (_, [1]) => await UserModel.[2]({ id: id }) } }
Drag options to blanks, or click blank then click option'
Aargs
Bparams
CfindOne
DfindAll
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'params' instead of 'args' for resolver arguments.
Using 'findAll' which returns multiple records instead of one.
5fill in blank
hard

Fill all three blanks to define a mutation that adds a new user with name and returns the created user.

GraphQL
type Mutation { addUser(name: [1]!): [2] } const resolvers = { Mutation: { addUser: async (_, [3]) => { const user = new UserModel({ name: name }); await user.save(); return user; } } }
Drag options to blanks, or click blank then click option'
AString
BUser
Cargs
DInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int for name which should be String.
Returning a scalar instead of User type.
Using wrong parameter name instead of 'args'.