Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ApolloMutation<TData, TVariables>

ApolloMutation

👩‍🚀 Custom element base class to issue mutations via your Apollo cache.

See ApolloMutationInterface for more information on events

element

Type parameters

  • TData

  • TVariables

Hierarchy

Implements

Index

Constructors

constructor

Properties

Private _document

_document: DocumentNode | null = null

Private _documentSetByJS

_documentSetByJS: boolean = false

Private _variables

_variables: TVariables | null = null

Private _variablesSetByJS

_variablesSetByJS: boolean = false

Optional awaitRefetchQueries

awaitRefetchQueries: undefined | false | true

called

called: boolean = false

client

client: ApolloClient<NormalizedCacheObject> | null = window.__APOLLO_CLIENT__ ?? null

Optional context

context: Record<string, unknown>

data

data: TData | null

error

error: Error | ApolloError | null

Optional errorPolicy

errorPolicy: ErrorPolicy

errors

errors: readonly GraphQLError[] | null

Optional fetchPolicy

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

ignoreResults

ignoreResults: boolean = false

loading

loading: boolean

Private mo

mo: MutationObserver | null = null

mostRecentMutationId

mostRecentMutationId: number = 0

mutation

mutation: DocumentNode

Optional optimisticResponse

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

refetchQueries

refetchQueries: MutationOptions<TData, TVariables>["refetchQueries"] | null = null

As an attribute, can be a string of comma-separated query names

<mutation-element refetch-queries="QueryA, QueryB,QueryC"></mutation-element>

As a property, you can pass any legal refetchQueries value.

variables

variables: TVariables | null

Static documentType

documentType: string = "mutation"

Accessors

document

Methods

Optional adoptedCallback

  • adoptedCallback(): void

Optional attributeChangedCallback

  • attributeChangedCallback(name: string, oldValue: string, newValue: string): void
  • Called when one of the element's observedAttributes changes.

    Parameters

    • name: string

      name of the observed attribute

    • oldValue: string

      previous value of the attribute. null if it was nonexistent

    • newValue: string

      current value of the attribute. null if removed.

    Returns void

connectedCallback

  • connectedCallback(): void

disconnectedCallback

  • disconnectedCallback(): void

Optional Protected documentChanged

Private generateMutationId

  • generateMutationId(): number

Private getDOMGraphQLDocument

Private getDOMVariables

  • getDOMVariables(): TVariables | null

Private isMostRecentMutation

  • isMostRecentMutation(mutationId: number): boolean
  • Returns true when an ID matches the most recent mutation id.

    Parameters

    • mutationId: number

    Returns boolean

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

Private onCompletedMutation

  • onCompletedMutation(mutationId: number, response: FetchResult<TData>): FetchResult<TData>
  • Callback for when a mutation is completed.

    Parameters

    • mutationId: number
    • response: FetchResult<TData>

    Returns FetchResult<TData>

Private onDOMMutation

  • onDOMMutation(records: MutationRecord[]): void

Optional onError

  • onError(_error: Error): void

Private onMutationError

  • onMutationError(mutationId: number, error: ApolloError): never

Optional updater

  • updater(...params: Parameters<MutationUpdaterFn<TData>>): ReturnType<MutationUpdaterFn<TData>>
  • Parameters

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

    Returns ReturnType<MutationUpdaterFn<TData>>

Optional Protected variablesChanged

  • variablesChanged(variables: TVariables | null): void