Created
January 26, 2019 00:02
-
-
Save scottdomes/31b0cfec1f6e8ab40870ff05b204b5ca to your computer and use it in GitHub Desktop.
This file contains 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 ApolloClient from 'apollo-boost'; | |
import { ApolloProvider, Query } from 'react-apollo'; | |
import { GET_CONTACTS } from './query'; | |
const client = new ApolloClient({ | |
uri: 'http://localhost:8080/graphql' | |
}); | |
const QueryComponent = ({ children }) => { | |
return ( | |
<ApolloProvider client={client}> | |
<Query query={GET_CONTACTS}> | |
{({ data, loading, error }) => { | |
if (error) { | |
return <div>Error!</div>; | |
} | |
if (loading) { | |
return <div>Loading...</div>; | |
} | |
return children(data); | |
}} | |
</Query> | |
</ApolloProvider> | |
); | |
}; | |
export default QueryComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment