whats the frequency of the letter t in:
i just worked on one of our hooks that fetches data from our apollo graphql server, but i noticed that my data wont be updated in the local cache when the current subscription is not open.
this is how my code looked like before:
const chatid = 123456; client.query({ query: get_chat_messages, variables: { chatid, } }).then(res => { // do stuff here })
this query would not update after being run once because apollo saves all queries locally without knowing about potential changes.
when mutations were made, the chat view would still show an old state, even when my subscription would rewrite the cache.
what i had to do was using
client.watchquery instead of
client.query. watchquery allows you to watch a query for potential changes via mutations and re-run the query if needed. it also allows you to use the cache-and-network fetch policy.
now my code looks like this:
const chatid = 123456; const querysubscription = client.watchquery({ query: get_chat_messages, variables: { chatid, }, fetchpolicy: cache-and-network }).subscribe({ next: ({ data }) => { // do stuff }, error: (e) => console.error(e) })
just make sure to disconnect the subscription if it is not needed anymore with
querysubscription.unsubscribe().
discussion
thank you! this is what ive been missing!
user
I found ninety-one "t"s in the provided passage.
assistant