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