Skip to content

Instantly share code, notes, and snippets.

@peggyrayzis
Created March 14, 2018 15:55
Show Gist options
  • Save peggyrayzis/cb40bc9145ef647f21316861f395518e to your computer and use it in GitHub Desktop.
Save peggyrayzis/cb40bc9145ef647f21316861f395518e to your computer and use it in GitHub Desktop.
Apollo Link State + React Apollo 2.1 = <3 <3 <3
import React from 'react';
import { ApolloConsumer, Query } from 'react-apollo';
import gql from 'graphql-tag';
const SimpleMutation = () => (
<ApolloConsumer>
{(cache) => (
<button onClick={() => cache.writeData({ data: { status: 'yo' }})}>Click me!</button>
)}
</ApolloConsumer>
)
// make sure to set an initial value for status in defaults when you initialize link-state
const QueryThatSubscribesToMutation = () => (
<Query query={gql`{ status @client }`}>
({ data, client }) => (
<div>
<p>{data.status}</p>
<button onClick={() => client.writeData({ data: { status: 'yo' }})}>Click me!</button>
</div>
)
</Query>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment