buildOperation()
function buildOperation(
name,
args,
fields,
argTypes?,
operation?): object;
Builds a parameterized GraphQL mutation document and its accompanying variables payload. Argument values are passed as GraphQL variables rather than interpolated into the query string, which lets the server coerce and validate them by type (including enums and input objects) and keeps the operation document constant across calls.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | undefined | The mutation field name, eg goto. |
args | Record<string, unknown> | null | undefined | Argument values keyed by argument name. undefined values are dropped. Pass null when the mutation takes no args. |
fields | string | undefined | The selection set for the mutation's response. |
argTypes | Record<string, string> | {} | Map of argument name → GraphQL type (eg String!), used to declare the operation's variables. Sourced from ARG_TYPES. |
operation | "mutation" | "subscription" | 'mutation' | The GraphQL operation type. Defaults to mutation; pass subscription to build a streaming operation. |
Returns
object
| Name | Type |
|---|---|
query | string |
variables | Record<string, unknown> |