Interface OperationContext

Additional metadata for an Operation used to execute it.

Remarks

The OperationContext is found on context and gives exchanges additional metadata and options used to execute the operation.

The context can often be changed on a per-operation basis, meaning, APIs on the Client or bindings can pass a partial context that alters these options for a single operation.

The OperationContext is populated mostly from the initial options passed to the Client at its time of creation, but may also be modified by exchanges when an Operation is passed through to the next exchange or when a result is returned.

Hierarchy

  • OperationContext

Indexable

[key: string]: any

Properties

_instance?: OperationInstance

A unique identity for GraphQL mutations.

Remarks

This is an internal property set by the Client to an identity of type OperationInstance. An OperationInstance is an identifier that's used to tell two mutation operations with identical query documents and variables apart from one another.

additionalTypenames?: string[]

Additional cache tags for @urql/core's document cacheExchange.

Remarks

The built-in cacheExchange in @urql/core is a document cache that uses __typenames in mutation results to invalidate past, cached queries. The additionalTypenames array may be set to the list of custom typenames whenever a result may not deliver __typename properties, e.g. when an empty array may be sent.

By providing a list of custom typenames you may "tag" a result as containing a certain type, which helps the document cache associate mutations with queries when either don't actually contain a __typename in the JSON result.

fetch?: ((input, init?) => Promise<Response>)

Type declaration

    • (input, init?): Promise<Response>
    • The fetch function used to make API calls.

      Remarks

      This is the fetch polyfill used by any fetch exchange to make an API request. By default, when this option isn't set, any fetch exchange will attempt to use the globally available fetch function to make a request instead.

      See

      https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API for the Fetch API spec.

      Parameters

      Returns Promise<Response>

fetchOptions?: RequestInit | (() => RequestInit)

Additional options passed to the fetch call on API requests.

Remarks

The options in this object or an object returned by a callback function will be merged into the RequestInit options passed to the fetch call.

See

https://developer.mozilla.org/en-US/docs/Web/API/fetch for a description of this object.

fetchSubscriptions?: boolean

Allows the fetchExchange to handle subscriptions.

Remarks

When set to true, subscriptions are allowed to be handled by the fetchExchange and will be sent using a fetch call as GraphQL over HTTP requests. This may be enabled on fetchSubscriptions when your API supports the text/event-stream and multipart/mixed response protocols and is able to use them to respond with subscription results.

Metadata that annotates an Operation in development for the urql-devtools.

Remarks

This is metadata that is used by the urql-devtools to get more information about Operations and OperationResults and is filled in by exchanges across the codebase in development.

This data is not for production use and hence shouldn't be used or relied upon directly. In production, this may not be set by default exchanges.

preferGetMethod?: boolean | "force" | "within-url-limit"

Instructs fetch exchanges to use a GET request.

Remarks

By default, GraphQL over HTTP requests are always sent as POST requests with a JSON body. However, sometimes it's preferable to send a GET request instead, for instance, for caching with or without persisted queries.

When set to true, the preferGetMethod instructs fetch exchanges to instead send a GET request for query operations.

Additionally, urql's built-in fetch exchanges will default to 'within-url-limit' and not send a GET request when the resulting URL would be 2,048 characters or longer. This can be forced and circumvented by setting this option to 'force'.

requestPolicy: RequestPolicy

The request and caching strategy instructing cache exchanges how to treat cached results.

Remarks

The RequestPolicy instructing cache exchanges how to use and treat their cached results. By default cache-first is set and used, which will use cache results, and only make an API request on a cache miss.

suspense?: boolean

A configuration flag indicating whether this operation may trigger "Suspense".

Remarks

This configuration flag is reserved for urql (react-urql) and @urql/preact to activate or deactivate support for Suspense, and is ignored in other bindings. When activated here and on Client.suspense it allows the bindings to "suspend" instead of returning a loading state, which will stop updates in a querying component and instead cascade to a higher suspense boundary for a loading state.

See

https://beta.reactjs.org/blog/2022/03/29/react-v18#new-suspense-features for more information on React Suspense.

url: string

The url passed to the fetch call on API requests.

See

https://developer.mozilla.org/en-US/docs/Web/API/fetch for a description of the fetch calls.

Generated using TypeDoc