Last active
August 12, 2018 02:51
-
-
Save slmyers/ef3a32bcdaa6afcb021c937cad4f0c25 to your computer and use it in GitHub Desktop.
Apollo client link example
This file contains 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
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