Skip to main content

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:

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.

Schema
{
"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.


args​

Type​

ParameterConfig?

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​

Schema
{
"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​

ParameterConfig?

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​

Schema
{
"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​

ParameterConfig?

Description​

Allows mapping from the QueryContext to the headers for the resolver request. For more information read about the Headers.


searchParams​

Type​

ParameterConfig?

Description​

Allows mapping from the QueryContext to the searchParams for the resolver request. For more information read about the SearchParams.