summaryrefslogtreecommitdiffstats
path: root/stepped-solutions/41/frontend/components/AddToCart.js
blob: 0625a9ce41c5d12ed8786dd9297c74e3b650a475 (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
import React from 'react';
import { Mutation } from 'react-apollo';
import gql from 'graphql-tag';

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,
        }}
      >
        {addToCart => <button onClick={addToCart}>Add To Cart 🛒</button>}
      </Mutation>
    );
  }
}
export default AddToCart;