As subject, below snippet explains my intention.
new ApolloLink((operation, forward) => {
const me = client.readQuery({
query: gql`
query meQuery {
Me @client {
name
age
}
}
`
});
console.log(me);
return forward!(operation);
}),
RM: I just make up the client object follow the Direct Cache Access section of the Apollo client's doc.
Why do I want to access the cache in the link chain?
Let say I need to refresh the idToken if it's expired, the refresh token logic should be done before the httpLink so that I can attach an non-expired token in the header. Also, if the refresh token process failed, I need to change the local state (apollo-link-state) sequentially and those components who is watching the local state can react upon the change.
@goldenbearkin you bet! You can do const { cache } = operation.getContext() to get access to the cache when using Apollo Client
Most helpful comment
@goldenbearkin you bet! You can do
const { cache } = operation.getContext()to get access to the cache when using Apollo Client