Skip to content

Instantly share code, notes, and snippets.

@MikeBild
Last active September 12, 2017 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MikeBild/cca8c44d3d0b4378d80c847f3c8877e6 to your computer and use it in GitHub Desktop.
Save MikeBild/cca8c44d3d0b4378d80c847f3c8877e6 to your computer and use it in GitHub Desktop.
API Prototype - compose React components to Higher-Order-Components with GraphQL Fragment / Query composer
export const Gists = props =>
<div>
{
props.viewer.gists &&
props.viewer.gists.map(x => <p>{x.description}</p>)
}
</div>
export const GistsWithGraphQL = compose(
withGraphQL(variables => Fragment`fragment gists on Gist {
description
}`)
)(Gists)
export const Gist = props =>
<h1>{props.viewer.gist.name}</h1>
export const GistWithGraphQL = compose(
withGraphQL(variables => Fragment`fragment gist on Gist {
name
}`)
)(Gist)
const GitHubGists = props =>
<div>
<GistsWithGraphQL />
<GistWithGraphQL />
</div>
export const GitHubGistsWithGraphQL = compose(
withGraphQL(({gistName}) => Query`{
viewer {
gists(first: 10) { nodes ${GistsWithGraphQL} }
gist(name: ${gistName}) ${GistWithGraphQL}
}
}`)
)(Gist)
render(<GitHubGistsWithGraphQL gistName={'cca8c44d3'}/>, document.getElementById('root'))
fragment gists on Gist {
description
}
fragment gist on Gist {
name
}
{
viewer {
gists(first: 10) { nodes {...gists} }
gist(name: "A") {...gist}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment