サブスクリプションでオプティミスティックUIを持つことは意味がありますか?Apollo jsサブスクリプションオプティミスティックUI
だから、基本的には:
addChannelMutation({
variables: { name: eventValue },
optimisticResponse: {
__typename: "Mutation",
addChannel: {
__typename: "Channel",
id: data.channels.length,
name: eventValue
}
},
update: (store, { data: { addChannel } }) => {
// Read the data from our cache for this query.
const data = store.readQuery({ query: channelsListQuery });
// Add our comment from the mutation to the end.
data.channels.push(addChannel);
// Write our data back to the cache.
store.writeQuery({ query: channelsListQuery, data });
}
}).then(res => {});
これは、重複キーの例外をトリガ二度同じ項目を追加します。 楽観主義はサブスクリプションで意味をなさないのですか?
ありがとうございます。それはまさに私がやっていることです。 –