Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ApolloMutation<TData, TVariables>

ApolloMutation

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

Type parameters

  • TData

  • TVariables

Hierarchy

Implements

Index

Constructors

constructor

Properties

Private __document

__document: DocumentNode = null

Private __mo

Optional awaitRefetchQueries

awaitRefetchQueries: boolean

called

called: boolean = false

client

Optional context

context: Record<string, unknown>

data

data: TData

error

error: Error

Optional errorPolicy

errorPolicy: ErrorPolicy

errors

errors: readonly GraphQLError[]

Optional fetchPolicy

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

ignoreResults

ignoreResults: boolean

loading

loading: boolean

mostRecentMutationId

mostRecentMutationId: number

mutation

mutation: DocumentNode

Optional optimisticResponse

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

refetchQueries

refetchQueries: MutationOptions["refetchQueries"] = 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

Accessors

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

Private generateMutationId

  • generateMutationId(): number
  • Increments and returns the most recent mutation id.

    Returns number

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: FetchResult<TData>): void
  • Parameters

    • _data: FetchResult<TData>

    Returns void

Private onCompletedMutation

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

    Parameters

    • response: FetchResult<TData>
    • mutationId: number

    Returns FetchResult<TData>

Optional onError

  • onError(_error: Error): void

Private onMutationError

  • onMutationError(error: ApolloError, mutationId: number): never
  • Callback for when a mutation fails.

    Parameters

    Returns never

Optional updater

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

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

    Returns ReturnType<MutationUpdaterFn<TData>>