Skip to content

Instantly share code, notes, and snippets.

@stolinski
Last active December 22, 2017 17:32
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/e6b8a1fd4c17c3a5e66d3b4bea87b3eb to your computer and use it in GitHub Desktop.
Save stolinski/e6b8a1fd4c17c3a5e66d3b4bea87b3eb to your computer and use it in GitHub Desktop.
Link State Meteor Not Working
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: authLink.concat(stateLink, httpLink),
cache,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment