-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
80 lines (70 loc) · 1.46 KB
/
App.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
import React from 'react';
import {Button, SafeAreaView} from 'react-native';
import {Header} from 'react-native/Libraries/NewAppScreen';
import {
ApolloClient,
ApolloProvider,
gql,
InMemoryCache,
useLazyQuery,
} from '@apollo/client';
import {MOCK_CONTACTS_DATA} from './mock-data';
const TYPE_DEFS = gql`
extend type Query {
contacts: [Contact!]
}
type Contact {
id: ID!
name: String!
thumbnailPath: String
phoneNumbers: [ContactPhoneNumber!]!
}
type ContactPhoneNumber {
id: ID!
number: String!
label: String!
}
`;
const RESOLVERS = {
Query: {contacts: () => MOCK_CONTACTS_DATA},
};
const client = new ApolloClient({
cache: new InMemoryCache(),
typeDefs: TYPE_DEFS,
resolvers: RESOLVERS,
});
const ALL_CONTACTS_QUERY = gql`
query AllContacts {
contacts @client {
id
name
phoneNumbers {
id
number
label
}
}
}
`;
function Content() {
const [queryContacts] = useLazyQuery(ALL_CONTACTS_QUERY, {
fetchPolicy: 'network-only',
});
const handlePress = async () => {
const time = performance.now();
await queryContacts();
console.log('Query execution time:', performance.now() - time);
};
return <Button title="Run query" onPress={handlePress} />;
}
function App() {
return (
<ApolloProvider client={client}>
<SafeAreaView>
<Header />
<Content />
</SafeAreaView>
</ApolloProvider>
);
}
export default App;