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