Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ApolloMutationInterface<TData, TVariables>

Type parameters

  • TData

  • TVariables

Hierarchy

Implemented by

Index

Properties

Optional awaitRefetchQueries

awaitRefetchQueries: boolean

Queries refetched as part of refetchQueries are handled asynchronously, and are not waited on before the mutation is completed (resolved). Setting this to true will make sure refetched queries are completed before the mutation is considered done. false by default.

called

called: boolean

Whether the mutation has been fired

client

The Apollo Client instance.

Optional context

context: Record<string, unknown>

Context to be passed to link execution chain.

data

data: TData

Latest mutation data.

document

document: DocumentNode

GraphQL operation document i.e. query, subscription, or mutation. Must be a parsed GraphQL DocumentNode, so use graphql-tag. If unset, the element can derive the document from the first light-DOM <script type="application/graphql"> child.

error

Latest error

Optional errorPolicy

errorPolicy: ErrorPolicy

Specifies the ErrorPolicy to be used for this mutation.

errors

errors: readonly GraphQLError[]

Latest errors

Optional fetchPolicy

fetchPolicy: Extract<FetchPolicy, "no-cache">

Specifies the FetchPolicy to be used for this mutation.

ignoreResults

ignoreResults: boolean

If true, the returned data property will not update with the mutation result.

loading

loading: boolean

Whether a request is in flight.

Private mostRecentMutationId

mostRecentMutationId: number

The ID number of the most recent mutation since the element was instantiated.

mutation

mutation: DocumentNode

The mutation.

Optional optimisticResponse

optimisticResponse: TData | ((vars: TVariables) => TData)

An object that represents the result of this mutation that will be optimistically stored before the server has actually returned a result.

This is most often used for optimistic UI, where we want to be able to see the result of a mutation immediately, and update the UI later if any errors appear.

Optional refetchQueries

refetchQueries: RefetchQueryDescription | ((result: FetchResult<TData>) => RefetchQueryDescription)

Specifies the FetchPolicy to be used for this mutation.

variables

variables: TVariables

An object that maps from the name of a variable as used in the mutation GraphQL document to that variable's value.

Methods

mutate

  • mutate(params?: Partial<MutationOptions<TData, TVariables>>): Promise<FetchResult<TData>>
  • This resolves a single mutation according to the options specified and returns a Promise which is either resolved with the resulting data or rejected with an error.

    Parameters

    • Optional params: Partial<MutationOptions<TData, TVariables>>

    Returns Promise<FetchResult<TData>>

Optional onCompleted

  • onCompleted(_data: TData): void
  • Callback for when a mutation is completed.

    Parameters

    • _data: TData

    Returns void

Optional onError

  • onError(_error: Error): void
  • Callback for when an error occurs in mutation.

    Parameters

    Returns void

Optional updater

  • updater(...params: Parameters<MutationUpdaterFn<TData>>): ReturnType<MutationUpdaterFn<TData>>
  • A function which updates the apollo cache when the query responds. This function will be called twice over the lifecycle of a mutation. Once at the very beginning if an optimisticResponse was provided. The writes created from the optimistic data will be rolled back before the second time this function is called which is when the mutation has succesfully resolved. At that point update will be called with the actual mutation result and those writes will not be rolled back.

    The reason a DataProxy is provided instead of the user calling the methods directly on ApolloClient is that all of the writes are batched together at the end of the update, and it allows for writes generated by optimistic data to be rolled back.

    Parameters

    • Rest ...params: Parameters<MutationUpdaterFn<TData>>

    Returns ReturnType<MutationUpdaterFn<TData>>