forked from expo/dev-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
86 lines (79 loc) · 1.84 KB
/
index.tsx
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { ApolloProvider, ApolloClient, InMemoryCache, useQuery, gql } from '@apollo/client';
import { StyleSheet, Text, View, Image, ScrollView } from 'react-native';
import { useApolloClientDevTools } from '@dev-plugins/apollo-client';
const client = new ApolloClient({
uri: 'https://flyby-router-demo.herokuapp.com/',
cache: new InMemoryCache(),
});
interface Location {
id: string;
name: string;
description: string;
photo: string;
}
const GET_LOCATIONS = gql`
query GetLocations {
locations {
id
name
description
photo
}
}
`;
export function Main() {
useApolloClientDevTools(client);
const { loading, error, data } = useQuery<{ locations: Location[] }>(GET_LOCATIONS);
if (loading) {
return <Text>Loading...</Text>;
}
if (error) {
return <Text>Error: </Text>;
}
const contents = data?.locations.map(({ id, name, description, photo }) => (
<View key={id} style={styles.item}>
<Text style={styles.name}>{name}</Text>
<Image source={{ uri: photo }} style={styles.photo} />
<Text style={styles.aboutCaption}>About this location:</Text>
<Text style={styles.description}>{description}</Text>
</View>
));
return <ScrollView>{contents}</ScrollView>;
}
export default function ApolloDemo() {
return (
<ApolloProvider client={client}>
<Main />
</ApolloProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
justifyContent: 'center',
marginTop: 60,
},
item: {
padding: 8,
marginVertical: 16,
flexDirection: 'column',
},
name: {
fontSize: 24,
fontWeight: 'bold',
},
photo: {
width: 350,
height: 200,
alignSelf: 'center',
marginVertical: 8,
},
aboutCaption: {
fontSize: 18,
marginVertical: 8,
},
description: {
fontSize: 12,
},
});