liaisev5.3.1
/createGraphQL options

Reference

createGraphQL options

This page lists every option createGraphQL(config) takes. Look here when you set up a GraphQL client and need an option’s exact type or default.

The config is a GraphQLBaseConfig, plus the operations: either operations, or queries and mutations.

OptionTypeDefaultWhat it does
endpointstringrequiredThe full URL of the GraphQL endpoint. It takes the place of baseUrl.
operationsan object of Operations—Each key becomes a method on the client, such as graphql.getCategory (Operation options).
queriesan object of Operations—Each key becomes a method under graphql.query, such as graphql.query.getCategory.
mutationsan object of Operations—Each key becomes a method under graphql.mutation, such as graphql.mutation.updateCategory.
middlewareMiddleware[]—Runs on every operation, before operation and call middleware.
headersHeadersInit—Sent with every operation. An operation or a call can replace a header. Content-Type is application/json unless you set your own.
fetchOptionsFetchOptions—Options passed through to fetch on every operation, such as credentials: 'include'. An operation or a call replaces a field (Cookies and other fetch options).
fetch(url: string, init: RequestInit) => Promise<Response>the global fetchThe fetch this client sends with, such as undici’s or mockFetch().fetch. Without it, liaise looks up the global fetch on every call, so a stub or polyfill installed later is used. It is called unbound, so window.fetch works as is. A method that needs its object, such as a Cloudflare service binding’s, goes in a wrapper: fetch: (url, init) => env.SERVICE.fetch(url, init). cacheMiddleware keys on which fetch sends a call, so clients with different fetch functions never share entries, even through one shared operation. Clients given the same function share entries. A wrapper created for each request, such as (url, init) => env.SERVICE.fetch(url, init) inside a client built per request, gets entries of its own, so a cache shared across requests never hits for it: create the wrapper once, outside the request, if those requests may share answers. Clients on the global fetch share as before.
timeoutnumber (ms)no deadlineOne deadline for every operation, retries included. An operation or a call can set its own, and 0 there turns it off.
logboolean | LogOptionsoffLogs every call to the console. Each line names the operation (Log every call, Log options).
onError(error: ApiError) => void—Called once per failed call, GraphQL errors included. Calls that share one failed request count as one. Never for 'abort'. If it throws, the caller still gets its Result.

Use operations for one flat client. To keep queries and mutations apart, use queries, mutations or both instead. TypeScript refuses operations together with either of the others. A query and a mutation may have the same name, and each runs its own operation (Queries and mutations).

A method takes the variables and an optional CallOptions, and returns a promise of a Result. An operation whose variables type is Record<string, never> is called with no arguments. Each method also has getHeaders().

createGraphQL throws if an operation sets both share and dedupe, as createApi does for an endpoint. A call never throws.

Next: Endpoint options lists what one REST endpoint can set.

esc