/
index.tsx
45 lines (41 loc) · 974 Bytes
/
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
import React from 'react';
import { gql, useQuery } from '@apollo/client';
import type { GitHubQueryDocument } from './__generated__/git-hub-query';
const repositoryFragment = gql`
fragment RepositoryFragment on Repository {
description
}
`;
const query = gql`
${repositoryFragment}
query GitHubQuery($first: Int!) {
viewer {
repositories(first: $first) {
nodes {
id
...RepositoryFragment
}
}
}
}
`;
const mutation = gql`
mutation UpdateMyRepository($repositoryId: ID!) {
updateRepository(input: { repositoryId: $repositoryId }) {
clientMutationId
}
}
`;
export default () => {
const { data } = useQuery(query as GitHubQueryDocument, { variables: { first: 100 } });
if (!data) return null;
return (
<ul>
{data.viewer?.repositories?.nodes?.map(repo => (
<li key={repo?.id}>
<span>{repo?.description}</span>
</li>
))}
</ul>
);
};