Last active
October 8, 2018 22:05
-
-
Save mariorodriguespt/2bf5869202f0d829dd9a1035017e0c66 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 ReactDOM from "react-dom"; | |
import { map } from "async"; | |
import { userInfo } from "os"; | |
import { ApolloProvider, Query } from "react-apollo"; | |
import ApolloClient from "apollo-boost"; | |
import gql from 'graphql-tag' | |
const client = new ApolloClient({ | |
uri: "http://localhost:4000/graphql" | |
}); | |
const Index = () => ( | |
<ApolloProvider client={client}> | |
<Query | |
query={ USERS_QUERY } | |
> | |
{({ loading, error, data }) => { | |
if( loading ){ | |
return 'Loading'; | |
} | |
return ( | |
<div> | |
<h2>My first Apollo app 🚀</h2> | |
<ul> | |
{ data.users.map(( user ) => ( | |
<li key={ user.id }>{ user.name }</li> | |
)) | |
} | |
</ul> | |
</div> | |
); | |
}} | |
</Query> | |
</ApolloProvider> | |
); | |
const USERS_QUERY = gql` | |
query Users { | |
users { | |
id | |
name | |
} | |
} | |
`; | |
ReactDOM.render(<Index />, document.getElementById("index")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment