Skip to content

Instantly share code, notes, and snippets.

@slmyers
Last active August 12, 2018 02:51
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 slmyers/ef3a32bcdaa6afcb021c937cad4f0c25 to your computer and use it in GitHub Desktop.
Save slmyers/ef3a32bcdaa6afcb021c937cad4f0c25 to your computer and use it in GitHub Desktop.
Apollo client link example
import { ApolloClient } from 'apollo-client';
import { withClientState } from 'apollo-link-state';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { resolvers, defaults } from './resolvers/message';
const typeDefs = `
interface Node {
id: ID!
}
type Message implements Node{
id: ID!
content: String!
author: String!
}
type Mutation {
addMessage(content: String!, author: String!): Message
}
type Query {
messages: [Message]
}
`;
const cache = new InMemoryCache({dataIdFromObject: object => object.id});
export const client = new ApolloClient({
cache,
link: withClientState({ resolvers, defaults, cache, typeDefs }),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment