summaryrefslogtreecommitdiffstats
path: root/components/Count.js
blob: 800a902aebf3894f41e995ea3ec183c5a1ced701 (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
36
37
import React, { Component } from 'react'
import { graphql, gql } from 'react-apollo'

import { ALL_ITEMS_QUERY } from '../queries';

class Count extends Component {

  render() {

    // 1
    if (this.props.allLinksQuery && this.props.allLinksQuery.loading) {
      return <div>Loading</div>
    }

    // 2
    if (this.props.allLinksQuery && this.props.allLinksQuery.error) {
      return <div>Error</div>
    }

    // 3
    const itemsToRender = this.props.allLinksQuery.allItems

    return (
      <div>
        <h1>There are {itemsToRender.length} items for sale</h1>
      </div>
    )
  }

}

// 1

// We export the graphQL HOC - this will fetch the data and inject it into the Count compeont via props

export { ALL_ITEMS_QUERY }
export default graphql(ALL_ITEMS_QUERY, { name: 'allLinksQuery' }) (Count)