UNPKG

1.1 kBMarkdownView Raw
1## Lunar Apollo
2
3Provides out of the box support for GraphQL, powered by [Apollo](https://www.apollographql.com).
4
5```bash static
6npm install @airbnb/lunar-apollo --save
7```
8
9This package relies on GraphQL related packages to also be installed.
10
11```bash static
12npm install graphql graphql-tag --save
13```
14
15## Setup
16
17Initialize the package to create an Apollo client. The following option settings may be passed to
18customize this package.
19
20- `links` (ApolloLink[]) - Collection of Apollo links (middleware) to apply to the client.
21
22```js static
23import Apollo, { HttpLink } from '@airbnb/lunar-apollo';
24
25const httpLink = new HttpLink({
26 uri: '/api/graphql',
27 credentials: 'same-origin',
28});
29
30Apollo.initialize({
31 links: [httpLink],
32});
33```
34
35> The client can be accessed with `Apollo.getClient()`.
36
37## Usage
38
39Once the Apollo client has been created, we can make it available to our queries and mutations by
40wrapping our application in a provider.
41
42```jsx static
43import { Provider } from '@airbnb/lunar-apollo';
44
45function Root() {
46 return (
47 <Provider>
48 <App />
49 </Provider>
50 );
51}
52```