summaryrefslogtreecommitdiffstats
path: root/components/Item.js
blob: 66ca66ff5e815f1d142a5030aae00717d399447c (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
import React, { Component } from 'react'
import { graphql, gql, compose } from 'react-apollo'
import { SINGLE_ITEM_QUERY } from '../queries';
import withData from '../lib/withData';

class Item extends Component {
  render() {
    if(!this.props.findItem.Item) return <p>Not ready</p>
    console.log(this.props.findItem.Item);

    if(this.props.loading) return <p>Loading...</p>
    if(this.props.error) return <p>Error...</p>

    const item = this.props.findItem.Item;
    return (
      <div>
        <h2>Viewing {item.title}</h2>
      </div>
    )
  }
}

const ComponentWithMutations = compose(
  graphql(SINGLE_ITEM_QUERY, {
    name: 'findItem',
    // This comes from Props
    options: ({ id }) => ({
      variables: { id }
    })
  })
)(Item);

export default ComponentWithMutations;