Skip to content

Instantly share code, notes, and snippets.

@unicodeveloper
Last active April 17, 2019 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unicodeveloper/717cc55792bfb13658e49e8cc789843a to your computer and use it in GitHub Desktop.
Save unicodeveloper/717cc55792bfb13658e49e8cc789843a to your computer and use it in GitHub Desktop.
import React from 'react';
import { Mutation } from 'react-apollo';
import { adopt } from 'react-adopt';
import { gql } from 'apollo-boost';
const INCREASE_COUNT = gql`
mutation increaseCount {
increaseCount {
id
currentCount
timestamp
}
}
`;
const UPDATE_TIMESTAMP = gql`
mutation updateTimestamp {
updateTimestamp {
id
currentCount
timestamp
}
}
`;
const increaseCount = ({ render }) => (
<Mutation mutation={INCREASE_COUNT}>
{(mutation, result) => render({ mutation, result })}
</Mutation>
);
const updateTimestamp = ({ render }) => (
<Mutation mutation={UPDATE_TIMESTAMP}>
{(mutation, result) => render({ mutation, result })}
</Mutation>
)
const Composed = adopt({
increaseCount,
updateTimestamp,
});
export const IncreaseCountButton = () => (
<Composed>
{(mutations) => {
return (
<button
type="button"
onClick={() => {
mutations.increaseCount.mutation();
mutations.updateTimestamp.mutation();
}}
>
Increase count
</button>
);
}}
</Composed>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment