-
-
Save idkjs/d71d9f8d4292017b595d6a25bc774097 to your computer and use it in GitHub Desktop.
API Prototype - compose React components to Higher-Order-Components with GraphQL Fragment / Query composer
This file contains hidden or 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
| 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')) |
This file contains hidden or 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
| 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