Created
November 6, 2017 18:55
-
-
Save brianlovin/9967a94e171d533620edfe41e7b30e81 to your computer and use it in GitHub Desktop.
Apollo query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! this works great! The code looks so much better.