Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Latest commit

 

History

History
51 lines (41 loc) · 786 Bytes

client-cheatsheet.md

File metadata and controls

51 lines (41 loc) · 786 Bytes

Client cheat sheet

Client & Provider

import ApolloClient from 'apollo-boost';
import { ApolloProvider } from 'react-apollo';

const client = new ApolloClient({
  uri: '[MY_GRAPHQL_ENDPOINT]',
  headers: {
    // ...
  },
});

<ApolloProvider client={client}>
  <App />
</ApolloProvider>;

Query

import gql from 'graphql-tag';
import { Query } from 'react-apollo';

<Query query={myQuery}>
  {({ data, loading, error }) => {
    // ...
  }}
</Query>;

Mutation

import gql from 'graphql-tag';
import { Mutation } from 'react-apollo';

<Mutation
  mutation={myMutation}
  variables={{}}
  onCompleted={data => {}}
  refetchQueries={[{ query: queryToRefetch, variables: {} }]}
  awaitRefetchQueries
>
  {mutate => (
    // ...
  )}
</Mutation>;