GraphQL Resolver
When writing queries and mutations that use a GraphQL service, you'll have access to two resolvers that execute queries and mutations on the connected service.
name
Type
string!
Values
graphql:query
graphql:mutation
fieldName
Type
string!
Description
A field name or path to anchor the GraphQL query to.
Example
If you query the original API with the following query:
{
characters {
results {
name
status
}
}
}
The fieldName
would be set to characters
, which is the field the query will be forwarded to on the origin.
{
site {
product(id: "UHJvZHVjdDo3Nw==") {
id
name
prices {
basePrice {
value
}
}
}
}
}
Set fieldName
to site.product
to use the namespaced product
query. The args
mapping will set arguments on product
.
options
The options object contains configuration specific to the type of resolver you select.
selectionSet
Type
string?
Description
Defines a GraphQL selectionSet, which is guaranteed to be included in the query to the origin API.
Example
When making this query:
{
RickAndMorty_myCharacters {
results {
name
}
}
}
A resolver with the following options would include status
and type
on every query to the origin, in addition to
whatever fields were requested originally.
{
"options": {
"fieldName": "characters",
"selectionSet": "{ status type }"
}
}
That data will still be excluded from your response data. This is useful if you need the data for other reasons—to transform it for a custom results field, or to use in a later resolver step.
ttl
Type
number?
Description
The number of seconds to cache query results for. This setting only applies to graphl:query
resolvers.
timeout
Type
number?
Description
The number of milliseconds to allowed before timing out. The default is no timeout.
unboxParentSelectionSet
Type
boolean?
Description
Default true
. Applicable when used with a selectionSet
including _parentFragment
. When true
, results are transformed so that the results from the parent fragment are at the top level. You can override this behavior by setting unboxParentSelectionSet
to false
, which could be useful if you want to inspect data that would otherwise be discarded.
Example
"getFirstCharacterEpisode": {
"resolver": {
"name": "graphql:query",
"service": "rick",
"fieldName": "character",
"options": {
"selectionSet": "{episode {..._parentFragment}}",
"unboxParentSelectionSet": false
},
"results": {
"ops": [{"path": "$", "mapping": "$finalResolver.episode[0]"}]
}
},
"args": {
"type": "object",
"properties": {"id": {"type": "string", "@tag": "id"}},
"required": ["id"]
},
"shape": "Rick_Episode"
}
args
Type
Description
Allows mapping from the QueryContext to the args values (input arguments) for the resolver. Results are not serialized. For more information read about the ParameterConfig.
Example
{
"RickAndMorty_characters": {
"resolver": {
"name": "graphql:query",
"service": "rick-and-morty",
"options": { "fieldName": "characters" },
"args": {
"ops": [
{
"path": "page",
"mapping": "$args.page"
},
{
"path": "filter",
"mapping": "$args.filter"
}
]
}
},
"args": {
"type": "object",
"properties": {
"page": { "type": "integer" },
"filter": { "@ref": "rick-and-morty:FilterCharacter" }
}
},
"shape": "RickAndMorty_Characters"
}
}
results
Type
Description
Allows mapping from the QueryContext to the results for the resolver step in a ComposeResolver or whole query. Results are not serialized. For more information read about the ParameterConfig.
Example
{
"RickAndMorty_characters": {
"resolver": {
"name": "graphql:query",
"service": "rick-and-morty",
"options": { "fieldName": "characters" },
"args": {
"ops": [
{
"path": "page",
"mapping": "$args.page"
},
{
"path": "filter",
"mapping": "$args.filter"
}
]
},
"results": {
"ops": [
{
"path": "$",
"mapping": "$finalStep.results"
}
]
}
},
"args": {
"type": "object",
"properties": {
"page": { "type": "integer" },
"filter": { "@ref": "rick-and-morty:FilterCharacter" }
}
},
"shape": {
"type": "array",
"items": {
"@ref": "RickAndMorty_Character"
}
}
}
}
headers
Type
Description
Allows mapping from the QueryContext to the headers for the resolver request. For more information read about the Headers.
searchParams
Type
Description
Allows mapping from the QueryContext to the searchParams for the resolver request. For more information read about the SearchParams.