GraphQL

Send GraphQL requests with the GraphQL built-in.
Airplane's GraphQL SDK makes it easy to issue one-off GraphQL queries from a task. To use this SDK, you'll need to configure a GraphQL resource.

Request

Perform a request against a GraphQL resource.
typescript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "get_user_profiles",
6
// Attach graphql resource to task
7
resources: ["profile_api"],
8
},
9
async (params) => {
10
const run = await airplane.graphql.request<{ { userId: string; avatar: string } }>(
11
// The slug of the GraphQL resource to query
12
"profile_api",
13
// The operation to execute
14
`query {
15
users {
16
id
17
name
18
email
19
}
20
}`
21
);
22
return run.output.data;
23
}
24
);
airplane.graphql.request(graphqlResource, operation, opts)
graphqlResource
REQUIRED
string

Slug of GraphQL resource to use. See Resources.

operation
REQUIRED
string

The GraphQL query or mutation to execute.

opts.variables
optional
Default
null
object

Optional GraphQL variables.

opts.headers
optional
Default
null
object

Optional object containing request headers.

opts.urlParams
optional
Default
null
object

Optional object containing URL parameters.

opts.retryFailures
optional
Default
false
boolean

True to retry the request on 500, 502, 503, and 504 error codes. Requests will always be retried on 408 and 429 error codes.

Returns
data
object

The return value from the GraphQL call.

errors
array

Any errors returned from the GraphQL server.