blob: 3e2842b7b6f2f03ff9e3c48d12889f11c3f79857 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import React from 'react';
import { Mutation } from 'react-apollo';
import gql from 'graphql-tag';
import { CURRENT_USER_QUERY } from './User';
const ADD_TO_CART_MUTATION = gql`
mutation addToCart($id: ID!) {
addToCart(id: $id) {
id
quantity
}
}
`;
class AddToCart extends React.Component {
render() {
const { id } = this.props;
return (
<Mutation
mutation={ADD_TO_CART_MUTATION}
variables={{
id,
}}
refetchQueries={[{ query: CURRENT_USER_QUERY }]}
>
{(addToCart, { loading }) => (
<button disabled={loading} onClick={addToCart}>
Add{loading && 'ing'} To Cart 🛒
</button>
)}
</Mutation>
);
}
}
export default AddToCart;
|