Created
June 1, 2019 16:18
-
-
Save kianaditya/270b2e876816d05b384218d4150dcd06 to your computer and use it in GitHub Desktop.
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
| import React from 'react' | |
| import { Query } from 'react-apollo' | |
| import gql from 'graphql-tag' | |
| const GET_CURRENT_USER = gql` | |
| { | |
| viewer { | |
| login | |
| name | |
| repositories(first: 10) { | |
| edges { | |
| node { | |
| name | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ` | |
| const GitProfile = () => ( | |
| <Query query={GET_CURRENT_USER}> | |
| {({ loading, error, data }) => { | |
| if (loading) return <h4>Loading</h4> | |
| if (error) console.log(error) | |
| const { | |
| viewer, | |
| viewer: { | |
| repositories: { edges } | |
| } | |
| } = data | |
| return ( | |
| <div> | |
| {viewer.name} {viewer.login} | |
| <ul> | |
| {edges.map(edge => { | |
| return <li>{edge.node.name}</li> | |
| })} | |
| </ul> | |
| </div> | |
| ) | |
| }} | |
| </Query> | |
| ) | |
| export default GitProfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment