-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
53 lines (50 loc) · 1.15 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
import { ReactNode } from "react";
import { P, match } from "ts-pattern";
import { useQuery } from "urql";
import UserList from "./components/UserList";
import { graphql } from "./gql";
import OrderList from "./components/OrderList";
// *NOTE*:
// eslint will complain if you violate the rules @graphql-eslint/recommended
const UsersDocument = graphql(`
query HomePageData {
...OrderListData
...UserListData
}
`);
function App() {
const [result] = useQuery({ query: UsersDocument });
return (
<div>
{match(result)
.returnType<ReactNode>()
.with(
{
fetching: true,
},
() => <div>Loading...</div>
)
.with(
{
error: P.nonNullable,
},
({ error }) => <div>{error.message}</div>
)
.with(
{
data: P.nonNullable,
},
({ data }) => (
<>
<UserList data={data} />
<OrderList data={data} />
</>
)
)
.otherwise(() => (
<div>Something went wrong!</div>
))}
</div>
);
}
export default App;