Created
December 28, 2017 22:07
-
-
Save stolinski/e89419a97ededa6dbeffb180ef384f3a to your computer and use it in GitHub Desktop.
apollo-linkp-state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out this is working, I was just hitting a bug with Apollo Link State not allowing client queries with server queries.