Resolver parameters
Resolvers receive 4 parameters.
1. Argument
The argument
field is the map of arguments received in the GraphQL query.
mutation AddMovie {
addMovie(title: "2001: A Space Odyssey", director: "Stanley Kubrick") {
title
director {
name
}
}
}
resolvers {
Mutation {
resolve("addMovie") {
val title = arguments["title"]
val directorName = arguments["director"]
}
}
}
2. Source
The source
parameter contains the parent object previously resolved.
Example:
type<Director>("Director") {
resolve("movies") {
source.name
}
}
3. Context
The context
parameter is the object returned by the context function.
4. Info
The info
parameter can provide you more information about the current GraphQL request.
resolvers {
Mutation {
resolve("addBook") {
val requestId = info.executionId
val selectedField = info.selectionSet.fields
}
}
}