Skip to content

Commit 9aefafd

Browse files
committed
feat(graphql): integrate graphql - author fetching, completed field
https://github.com/martis-git/learn-frontend/issues/279
1 parent aaecc39 commit 9aefafd

File tree

7 files changed

+27
-18
lines changed

7 files changed

+27
-18
lines changed

examples/graphql/src/pages/task-details/query.gen.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ export type TodoQueryVariables = Types.Exact<{
88
}>;
99

1010

11-
export type TodoQuery = { readonly todo?: Types.Maybe<{ readonly id?: Types.Maybe<string>, readonly title?: Types.Maybe<string>, readonly user?: Types.Maybe<{ readonly id?: Types.Maybe<string>, readonly name?: Types.Maybe<string> }> }> };
11+
export type TodoQuery = { readonly todo?: Types.Maybe<{ readonly id?: Types.Maybe<string>, readonly title?: Types.Maybe<string>, readonly completed?: Types.Maybe<boolean>, readonly user?: Types.Maybe<{ readonly username?: Types.Maybe<string>, readonly email?: Types.Maybe<string>, readonly company?: Types.Maybe<{ readonly name?: Types.Maybe<string> }> }> }> };
1212

1313

1414
export const TodoDocument = gql`
1515
query Todo($id: ID!) {
1616
todo(id: $id) {
1717
id
1818
title
19+
completed
1920
user {
20-
id
21-
name
21+
username
22+
email
23+
company {
24+
name
25+
}
2226
}
2327
}
2428
}

examples/graphql/src/pages/task-details/query.gql

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ query Todo($id: ID!) {
22
todo(id: $id) {
33
id
44
title
5+
completed
56
user {
6-
id
7-
name
7+
username
8+
email
9+
company {
10+
name
11+
}
812
}
913
}
10-
}
14+
}

examples/graphql/src/pages/tasks-list/query.gen.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as Apollo from '@apollo/client';
66
export type TodosQueryVariables = Types.Exact<{ [key: string]: never; }>;
77

88

9-
export type TodosQuery = { readonly todos?: Types.Maybe<{ readonly data?: Types.Maybe<ReadonlyArray<Types.Maybe<{ readonly id?: Types.Maybe<string>, readonly title?: Types.Maybe<string>, readonly user?: Types.Maybe<{ readonly id?: Types.Maybe<string>, readonly name?: Types.Maybe<string> }> }>>> }> };
9+
export type TodosQuery = { readonly todos?: Types.Maybe<{ readonly data?: Types.Maybe<ReadonlyArray<Types.Maybe<{ readonly id?: Types.Maybe<string>, readonly title?: Types.Maybe<string>, readonly completed?: Types.Maybe<boolean>, readonly user?: Types.Maybe<{ readonly username?: Types.Maybe<string> }> }>>> }> };
1010

1111

1212
export const TodosDocument = gql`
@@ -15,9 +15,9 @@ export const TodosDocument = gql`
1515
data {
1616
id
1717
title
18+
completed
1819
user {
19-
id
20-
name
20+
username
2121
}
2222
}
2323
}

examples/graphql/src/pages/tasks-list/query.gql

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ query Todos {
33
data {
44
id
55
title
6+
completed
67
user {
7-
id
8-
name
8+
username
99
}
1010
}
1111
}

examples/graphql/src/shared/components/task-card/index.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import cn from "classnames";
33
import { Card, Steps, Typography, Divider } from "antd";
44
import { UserOutlined, HomeOutlined } from "@ant-design/icons";
5-
import { useFetch } from "shared/hooks";
65
import "./index.scss";
76

87
type Props = import("models").Todo;
@@ -20,7 +19,6 @@ const getTaskStatus = (completed: boolean) => {
2019
// TODO: as feature
2120
const TaskCard = (props: Props) => {
2221
const { completed, title, user } = props;
23-
const { data: author } = useFetch<import("models").User>(`users/${user?.id}`);
2422

2523
return (
2624
<Card
@@ -34,9 +32,9 @@ const TaskCard = (props: Props) => {
3432
<div className="task-card__author">
3533
<Typography.Title level={5}>Author</Typography.Title>
3634
<span className="task-card__author" >
37-
<UserOutlined style={ICON_STYLE} /> {author?.username} {`<${author?.email}>`}
35+
<UserOutlined style={ICON_STYLE} /> {user?.username} {`<${user?.email}>`}
3836
<br />
39-
<HomeOutlined style={ICON_STYLE} /> {author?.company.name}
37+
<HomeOutlined style={ICON_STYLE} /> {user?.company.name}
4038
</span>
4139
</div>
4240
<Divider />

examples/graphql/src/shared/components/task-item/index.scss

+5
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@
2020
color: rgba(cornflowerblue, 0.8);
2121
}
2222
}
23+
24+
&__author {
25+
display: flex;
26+
align-items: center;
27+
}
2328
}

examples/graphql/src/shared/components/task-item/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ import React from 'react'
22
import cn from "classnames";
33
import { Card } from "antd";
44
import { UserOutlined } from "@ant-design/icons";
5-
import { useFetch } from "shared/hooks";
65
import "./index.scss";
76

87
type Props = import("models").Todo;
98

109
// TODO: as feature
1110
const TaskItem = (props: Props) => {
1211
const { completed, title, user, id } = props;
13-
const { data: author } = useFetch<import("models").User>(`users/${user?.id}`);
1412

1513
return (
1614
<Card className={cn("task-item", { completed })}>
1715
<a className="task-item__title" href={`/${id}`}>{title}</a>
1816
<span className="task-item__author" >
1917
<UserOutlined />
20-
{author?.username}
18+
{user?.username}
2119
</span>
2220
</Card>
2321
)

0 commit comments

Comments
 (0)