Skip to content

Instantly share code, notes, and snippets.

@scottdomes
Created January 26, 2019 00:02
Show Gist options
  • Save scottdomes/31b0cfec1f6e8ab40870ff05b204b5ca to your computer and use it in GitHub Desktop.
Save scottdomes/31b0cfec1f6e8ab40870ff05b204b5ca to your computer and use it in GitHub Desktop.
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