Skip to main content
The GraphQLResourceClient allows you to execute GraphQL queries and mutations against your configured endpoint.

Usage

import { myGraphQLClient } from "./clients";

const result = await myGraphQLClient.invoke(
  "POST",
  "/graphql",
  "fetch-users",
  {
    body: {
      type: "json",
      value: {
        query: `query { users { id name email } }`,
      },
    },
  }
);

if (result.ok && result.result.body.kind === "json") {
  console.log("Users:", result.result.body.value);
}

Per-Request Headers

You can pass arbitrary HTTP headers on a per-request basis. Per-request headers override the resource’s configured auth header if they use the same header name. This is useful for passing request IDs, tenant headers, or additional auth tokens:
const result = await myGraphQLClient.invoke(
  "POST",
  "/graphql",
  "fetch-users",
  {
    body: {
      type: "json",
      value: {
        query: `query { users { id name email } }`,
      },
    },
    headers: {
      "X-Request-ID": "req-12345",
      "X-Tenant-ID": "tenant-abc",
      "Authorization": "Bearer custom-token",
    },
  }
);

Inputs

The invoke method accepts the following arguments:
method
string
required
The HTTP method to use. Typically "POST" for GraphQL.
path
string
required
The GraphQL endpoint path (e.g., /graphql).
invocationKey
string
required
A unique identifier for this operation.
options
object
Optional configuration object.

Outputs

The output format is the same as the Custom API client.
kind
"api"
Discriminator for the response type.
status
number
The HTTP status code.
body
ResponseBody
The response body containing the GraphQL result.