You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering a problem where if I don't spread context in operation.setContext, then the cache is unavailable in my client state resolver. According to the apollo boost example, this should work.
constclient=newApolloClient({uri: config.apiUrl,fetchOptions: {credentials: 'include'},request: operation=>{consttoken=localStorage.getItem(config.tokenName);operation.setContext(ctx=>({// This seems to fix the problem. It's as if the rest of the// existing context is not passed but I thought it gets merged?
...ctx,headers: {authorization: token ? `Bearer ${token}` : null}}));},clientState: {defaults: {isLoggedIn: false},resolvers: {Mutation: {updateAuthStatus: (_,{ loggedIn, token },ctx)=>{constisLoggedIn=loggedIn;// if I dont spread ctx in the request middleware, `cache` isn't available. Instead I just get `{headers:{...}}`if(loggedIn===true&&token){window.localStorage.setItem(config.tokenName,token);}elseif(loggedIn===false){window.localStorage.removeItem(config.tokenName);}constdata={
isLoggedIn
};ctx.cache.writeData({ data });returnnull;}}}}});
How I'm using it. authed.js helper render prop component
Ooops - the apollo-boost options listed in the README are out of date. Please refer to the main Apollo Client API docs for the proper ApolloClient constructor options. I'll get the README updated accordingly. Thanks!
The Apollo Boost README config options section, and provided
config example, are outdated and have caused some confustion for
people. Since we already have everything up to date in the
official docs, this commit removes the duplicated (and invalid)
section from the README, replacing it with a link to the docs.
Fixes#3210.
I'm encountering a problem where if I don't spread context in
operation.setContext
, then thecache
is unavailable in my client state resolver. According to the apollo boost example, this should work.How I'm using it.
authed.js helper render prop component
Intended outcome:
cache should be available in resolver context
Actual outcome:
stack trace
How to reproduce the issue:
I tried setting this up on codesandbox
https://codesandbox.io/s/n55oo5zq6j
but it's not creating the same issue. I have so much other code in my app so maybe it's something with that
Version
The text was updated successfully, but these errors were encountered: