-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
62 lines (45 loc) · 1.18 KB
/
App.js
File metadata and controls
62 lines (45 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react';
import { Text, View, SafeAreaView } from 'react-native';
// import { ApolloProvider, graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-boost';
import { ApolloProvider, graphql } from 'react-apollo';
// Main App export
export default class ApolloApp extends React.Component {
render() {
return(
<ApolloProvider client={client}>
<SafeAreaView>
<MovieDetails />
</SafeAreaView>
</ApolloProvider>
);
}
}
// Apollo client
const client = new ApolloClient({
link: new HttpLink({ uri: 'http://192.168.0.103:4000/' }),
cache: new InMemoryCache().restore({}),
});
// Example query from https://www.graph.cool/
const MOVIE_QUERY = gql`
{
randomPerson {
id
employee_name
employee_salary
}
}
`;
// MovieDetails Component
const MovieDetails = graphql(MOVIE_QUERY)(({ data }) => {
const { error, randomPerson } = data;
if (error) {
return <Text>{error.message}</Text>;
}
if (randomPerson) {
return (<Text>{randomPerson.id} {randomPerson.employee_name}</Text>
)
}
return <Text>Loading...</Text>;
});