Skip to content

Instantly share code, notes, and snippets.

@mlg87
Created July 21, 2020 21:05
Show Gist options
  • Save mlg87/398d468f3b4295e03b8ddbd539074e2a to your computer and use it in GitHub Desktop.
Save mlg87/398d468f3b4295e03b8ddbd539074e2a to your computer and use it in GitHub Desktop.
Using Apollo Client for global state management code samples - src/client.ts
// src/client.ts
import { InMemoryCache } from 'apollo-cache-inmemory';
import balloonDefaultCacheValues from './Balloon/defaults';
import { setSelectedBalloonMutationResolver } from './Balloon/mutations';
import balloonSchema from './Balloon
const cache = new InMemoryCache();
export const client = new ApolloClient({
...
cache,
resolvers: {
Mutation: {
setSelectedBalloon: setSelectedBalloonMutationResolver
}
},
typeDefs: [balloonSchema]
});
// init cache
cache.writeData({
data: {
...balloonDefaultCacheValues
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment