Skip to content

Instantly share code, notes, and snippets.

@stolinski
Created December 28, 2017 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stolinski/e89419a97ededa6dbeffb180ef384f3a to your computer and use it in GitHub Desktop.
Save stolinski/e89419a97ededa6dbeffb180ef384f3a to your computer and use it in GitHub Desktop.
apollo-linkp-state
const httpLink = new HttpLink({ uri: Meteor.absoluteUrl('graphql') });
const authLink = new ApolloLink((operation, forward) => {
const token = Accounts._storedLoginToken(); // from local storage
operation.setContext(() => ({
headers: {
'meteor-login-token': token,
},
}));
return forward(operation);
});
const cache = new InMemoryCache().restore(window.__APOLLO_STATE__);
const stateLink = withClientState({
cache,
resolvers: {
Mutation: {
updateNetworkStatus: (_, { isConnected }, { cache }) => {
const data = {
networkStatus: { isConnected },
};
cache.writeData({ data });
},
},
},
defaults: {
networkStatus: {
__typename: 'NetworkStatus',
isConnected: true,
},
},
});
const client = new ApolloClient({
link: from([stateLink, authLink, httpLink]),
cache,
});
@stolinski
Copy link
Author

Turns out this is working, I was just hitting a bug with Apollo Link State not allowing client queries with server queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment