5
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.

Apollo ClientでIDなしオブジェクトのフィールドを含めたレスポンスでキャッシュを更新しようとすると怒られる

Posted at

Store error: the application attempted to write an object with no provided id but the store already contains an id of Hogehoge for this object.

Apollo Clientで、以下のようなqueryによって取得/キャッシュされたnoteオブジェクトがあったとして

query notes {
  notes {
    id
    content
    author {
      id
      name
    }
  }
}

キャッシュされているnoteオブジェクトを更新するようなmutationのフィールドが以下のようになっていた場合

mutation updateNote($input: UpdateNoteInput!) {
  updateNote(input: $input) {
    id
    content
    author {
      name
    }
  }
}

authorにidがないため、見出しのようなエラーが出る。
ちなみに以下のようなフィールドにするとエラーは出ないがエンティティを特定できないため当然キャッシュは更新されない。

mutation updateNote($input: UpdateNoteInput!) {
  updateNote(input: $input) {
    content
    author {
      id
      name
    }
  }
}
5
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
5
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?