LoginSignup
1
1

More than 3 years have passed since last update.

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

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