Files
apollo/docs/guide/components/mutation.md
T
2019-05-02 17:23:39 +02:00

754 B

ApolloMutation

You can use the ApolloMutation (or apollo-mutation) component to call Apollo mutations directly in your template.

Here is an example:

<ApolloMutation
  :mutation="gql => gql`
    mutation DoStuff ($name: String!) {
      someWork (name: $name) {
        success
        timeSpent
      }
    }
  `"
  :variables="{
    name
  }"
  @done="onDone"
>
  <template v-slot="{ mutate, loading, error }">
    <button :disabled="loading" @click="mutate()">Click me</button>
    <p v-if="error">An error occured: {{ error }}</p>
  </template>
</ApolloMutation>

See ApolloQuery to learn how to write GraphQL queries in the template.

See API Reference for all the available options.