Skip to content

Instantly share code, notes, and snippets.

@SaraVieira
Created March 31, 2018 20:36
Show Gist options
  • Save SaraVieira/d54e3dda3fe5f4e71addb2697c68655e to your computer and use it in GitHub Desktop.
Save SaraVieira/d54e3dda3fe5f4e71addb2697c68655e to your computer and use it in GitHub Desktop.
<script>
import { GET_NAMES, ADD_NAME } from "../queries";
export default {
name: "Form",
data() {
return {
person: ""
};
},
methods: {
onSubmit() {
const name = this.person;
this.person = "";
this.$apollo.mutate({
mutation: ADD_NAME,
variables: {
name
},
update: (cache, { data: { createNames } }) => {
const { allNameses } = cache.readQuery({ query: GET_NAMES });
cache.writeQuery({
query: GET_NAMES,
data: {
allNameses: allNameses.concat(createNames)
}
});
}
})
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment