Skip to content

Instantly share code, notes, and snippets.

@peltho
Created June 1, 2020 16:24
Show Gist options
  • Save peltho/2dcd339f899c3846811f1ebd3b452466 to your computer and use it in GitHub Desktop.
Save peltho/2dcd339f899c3846811f1ebd3b452466 to your computer and use it in GitHub Desktop.
react native ac3 poc
// index.js
// ...
import { ApolloClient, ApolloProvider, HttpLink, InMemoryCache } from '@apollo/client';
const client = new ApolloClient({
link: new HttpLink({
uri: 'http://192.168.1.47:8090/graphql'
}),
cache: new InMemoryCache()
});
const App = () => (
<ApolloProvider client={client}>
<RootNavigator />
</ApolloProvider>
)
AppRegistry.registerComponent(appName, () => App);
// RootNavigator
// ...
import { useQuery, gql } from '@apollo/client';
const ALL_HUMANS = gql`
query {
humans {
id
name
}
}
`;
// The query above works well in graphiQL at http://192.168.1.47:8090/graphql
export const RootNavigator = () => {
const { loading, error, data } = useQuery(ALL_HUMANS);
if (loading) console.log('loading...') // It only displays this log all the time
if (error) console.log('error')
if (error) console.log(error.message)
if (!loading && data) {
console.log("data:");
console.log(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment