Skip to content

Instantly share code, notes, and snippets.

@brianlovin
Created November 6, 2017 18:55
Show Gist options
  • Save brianlovin/9967a94e171d533620edfe41e7b30e81 to your computer and use it in GitHub Desktop.
Save brianlovin/9967a94e171d533620edfe41e7b30e81 to your computer and use it in GitHub Desktop.
Apollo query
import React, { Component } from 'react'
import compose from 'recompose/compose'
import { gql, graphql } from 'react-apollo'
import List from './List'
class Images extends Component {
render () {
const { loading, error, allGalleries } = this.props.allImages
if (allGalleries && allGalleries.length > 0) {
return (
<div>
{allGalleries.map(image => <List key={image.id} image={image} />)}
</div>
)
}
if (loading) {
return <div>loading...</div>
}
if (error) {
return <div>error...</div>
}
return null
}
}
const ALL_IMAGES_QUERY = gql`
query allGalleriesQuery {
allGalleries {
id
description
picture {
url
}
}
}
`
const ALL_IMAGES_OPTIONS = { name: 'allImages' }
const getAllGalleries = graphql(ALL_IMAGES_QUERY, ALL_IMAGES_OPTIONS)
export default compose(getAllGalleries)(Images)
Copy link

ghost commented Nov 6, 2017

Thank you! this works great! The code looks so much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment