-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.tsx
78 lines (69 loc) · 1.49 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
/* eslint-disable @typescript-eslint/no-unused-vars */
import React from "react";
import { useQuery } from "@apollo/client";
import "./App.css";
import Video from "./Video";
import { graphql } from "./gql/gql";
import { getFragmentData } from "./gql";
const episodeFragment = graphql(/* GraphQL */ `
fragment EpisodeFragment on Episode {
id
title
show {
id
title
}
releaseDate
__typename
}
`);
const movieFragment = graphql(/* GraphQL */ `
fragment MovieFragment on Movie {
id
title
collection {
id
}
releaseDate
__typename
}
`);
const videoDetailsFragment = graphql(/* GraphQL */ `
fragment DetailsFragment on Video {
title
__typename
...MovieFragment
...EpisodeFragment
}
`);
const videoQueryDocument = graphql(/* GraphQL */ `
query Video($id: ID!) {
video(id: $id) {
...DetailsFragment
__typename
}
}
`);
function App() {
const { data } = useQuery(videoQueryDocument, {
variables: { id: "10" },
});
const videoDetail = getFragmentData(videoDetailsFragment, data?.video);
const movie =
videoDetail && videoDetail.__typename === "Movie"
? getFragmentData(movieFragment, videoDetail)
: null;
// ^?
return (
<div className="App">
{data && (
<ul>
{/* {data.allFilms?.edges?.map(
(e, i) => e?.node && <Video film={e?.node} key={`film-${i}`} />
)} */}
</ul>
)}
</div>
);
}
export default App;