Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Created June 1, 2019 16:18
Show Gist options
  • Save kianaditya/270b2e876816d05b384218d4150dcd06 to your computer and use it in GitHub Desktop.
Save kianaditya/270b2e876816d05b384218d4150dcd06 to your computer and use it in GitHub Desktop.
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