1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vue + Apollo + GraphQLを使っていてmutationの後にUIが更新されない場合

1
Posted at

Apolloを使っていてmutationを使ってデータの更新をした場合、updateを呼んでキャッシュを更新する必要がありました。ドキュメントに書いていたけど見つけるまでハマったのでメモ。

updateRelationship(relationship, variables) {
        this.$apollo.mutate({
          mutation: updateCompanyUserRelationship,
          variables: variables,
          // updateを呼んであげる
          update: (store, {data: {todo}}) => {
            const data = store.readQuery({query: userQuery, variables: {company_id: this.currentCompany.id}});
            store.writeQuery({
              query: userQuery,
              variables: {
                company_id: this.currentCompany.id
              },
              data
            });
          },
        }).then(() => {
          this.$notify({
            group: 'foo',
            title: 'ユーザー情報を更新しました。',
          });
          this.$refs['modal'].hide();
          this.refresh();
        });
      },
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?