Created
November 26, 2018 17:09
-
-
Save stubailo/ccbb3539d5fab3ebebddb11f584386cd to your computer and use it in GitHub Desktop.
How to import your mocked schema and pass it to Apollo Client
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
import { ApolloClient } from 'apollo-client'; | |
import { InMemoryCache } from 'apollo-cache-inmemory'; | |
import { SchemaLink } from 'apollo-link-schema'; | |
// Import the schema object from previous code snippet above | |
import schema from './path/to/your/schema'; | |
const client = new ApolloClient({ | |
cache: new InMemoryCache(), | |
link: new SchemaLink({ schema }) | |
}); | |
// Then, put this client in ApolloProvider | |
import { ApolloProvider } from 'react-apollo'; | |
// Wherever we want a component to display mocked data | |
// MyComponent uses the Query component internally | |
<ApolloProvider client={client}> | |
<MyComponent /> | |
</ApolloProvider> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment