REST Resolver
When writing queries and mutations that use a REST service, you'll have access to resolvers that execute many of the standard HTTP request methods on the connected service.
name
The REST resolver name
determines the REST method to be used in the request.
values
rest:get
rest:post
rest:delete
rest:head
rest:put
rest:patch
path
Type
(ParameterConfig | string)!
Description
The resource path your resolver is accessing on the REST service. This is appended to the service's base path when making requests.
The path can be a string
or a ParameterConfig
object. As a string
it will be appended, as a
ParameterConfig
it will be processed and placed in the serialize.template
. Read more about the
path config.
options
The options object contains configuration specific to the type of resolver you select.
timeout
Type
number?
Description
The number of milliseconds to allowed before timing out. The default is no timeout.
ttl
Type
number?
Description
A time in milliseconds to cache a response.
The number of seconds to cache request results for. This setting only applies to rest:get
resolvers.
retry
Type
number | RetryOptions?
Description
A number or object that is passed through to the got retry config.
If a retry configuration is specified in both the resolver options and the service configuration, the retry configurations are merged with the resolver taking precedence.
trailingSlash
Type
boolean?
Description
If set to true
will ensure your URLs have a trailing slash. If set to false
will ensure they do not.
ignoreErrors
Type
boolean?
Description
If set to true
any error response will return null
instead of throwing the error. This is helpful in situations where you would not want to blow up your entire response for an error in a single field. For instance, in an @resolver
, this would allow for the parent object's data to change in ways that may not be acceptable for your REST request.
Example
{
"MyShape": {
"id": "MyShape",
"name": "MyShape",
"title": "MyShape",
"schema": {
"type": "object",
"properties": {
"myExternalId": {
"type": "string"
},
"myExternalObject": {
"@resolver": {
"if": "!isEmpty($source.myExternalId)",
"name": "rest:get",
"service": "my-service",
"path": {
"ops": [
{
"path": "objectId",
"mapping": "$source.myExternalId"
}
],
"serialize": {
"template": "objects/{objectId}"
}
},
"options": {
"ignoreErrors": true
}
}
}
}
}
}
}
let results = {
errors: [
{
message: 'bad-value is a no good',
locations: [
{
line: 2,
column: 25
}
],
type: 'GraphQLError'
}
]
};
let results = {
data: {
myExternalId: 'bad-value',
myExternalObject: null
}
};
let results = {
data: {
myExternalId: 'good-value',
myExternalObject: {
id: 'good-value',
goodTimes: 'Great Oldies'
}
}
};
searchParams
Type
Description
Allows mapping from the QueryContext to the searchParams (or query params) for the resolver's request. For more information read about the Resolver.searchParams property.
form
Type
Description
Allows mapping from the QueryContext to a form body for the resolver's request. For more information read about the Resolver.form property.
json
Type
Description
Allows mapping from the QueryContext to a JSON object for the resolver's request. For more information read about the Resolver.json property.
body
Type
Description
Allows mapping from the QueryContext to the body for the resolver's request. For more information read about the Resolver.body property.
headers
Type
Description
Allows mapping from the QueryContext to the headers for the resolver's request. For more information read about the Resolver.headers property.
results
Type
Description
Allows mapping from the QueryContext to the headers for the resolver's request. For more information read about the Resolver.results property.