Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit d11740a

Browse files
committed
move fragments closer to usage
1 parent 2f79778 commit d11740a

File tree

3 files changed

+54
-38
lines changed

3 files changed

+54
-38
lines changed

example-hooks-gen/ts/components/Todo.tsx

+20-10
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ interface Props {
3636
}
3737

3838
graphql`
39-
fragment TodoData on Todo {
40-
complete
41-
id
42-
text
43-
}
44-
fragment TodoViewer on User {
45-
id
46-
totalCount
47-
completedCount
48-
}
4939
mutation TodoRemoveMutation($input: RemoveTodoInput!) {
5040
removeTodo(input: $input) {
5141
deletedTodoId
@@ -55,6 +45,9 @@ graphql`
5545
}
5646
}
5747
}
48+
`
49+
50+
graphql`
5851
mutation TodoRenameMutation($input: RenameTodoInput!) {
5952
renameTodo(input: $input) {
6053
todo {
@@ -63,6 +56,9 @@ graphql`
6356
}
6457
}
6558
}
59+
`
60+
61+
graphql`
6662
mutation TodoChangeStatusMutation($input: ChangeTodoStatusInput!) {
6763
changeTodoStatus(input: $input) {
6864
todo {
@@ -80,8 +76,22 @@ graphql`
8076
const Todo = (props: Props) => {
8177
const [isEditing, setIsEditing] = React.useState(false)
8278

79+
graphql`
80+
fragment TodoData on Todo {
81+
complete
82+
id
83+
text
84+
}
85+
`
8386
const todo = useTodoDataFragment(props.todo)
8487

88+
graphql`
89+
fragment TodoViewer on User {
90+
id
91+
totalCount
92+
completedCount
93+
}
94+
`
8595
const viewer = useTodoViewerFragment(props.viewer)
8696

8797
const [commitRename] = useTodoRenameMutation()

example-hooks-gen/ts/components/TodoApp.tsx

+19-16
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,14 @@ interface Props {
2929
}
3030

3131
graphql`
32-
fragment TodoAppData on User
33-
@refetchable(queryName: "TodoAppRefetchQuery")
34-
@argumentDefinitions(
35-
last: { type: "Int" }
36-
first: { type: "Int" }
37-
after: { type: "String" }
38-
before: { type: "String" }
39-
) {
40-
id
41-
totalCount
42-
isAppending
43-
...TodoListFooterData
44-
...TodoList
45-
@arguments(last: $last, first: $first, after: $after, before: $before)
46-
}
47-
4832
mutation TodoAppSetAppendingMutation($isAppending: Boolean!) {
4933
setAppending(appending: $isAppending) {
5034
isAppending
5135
}
5236
}
37+
`
5338

39+
graphql`
5440
mutation TodoAppAddTodoMutation(
5541
$input: AddTodoInput!
5642
$connections: [ID!]!
@@ -85,6 +71,23 @@ graphql`
8571
let tempID = 0
8672

8773
const TodoApp = (props: Props) => {
74+
graphql`
75+
fragment TodoAppData on User
76+
@refetchable(queryName: "TodoAppRefetchQuery")
77+
@argumentDefinitions(
78+
last: { type: "Int" }
79+
first: { type: "Int" }
80+
after: { type: "String" }
81+
before: { type: "String" }
82+
) {
83+
id
84+
totalCount
85+
isAppending
86+
...TodoListFooterData
87+
...TodoList
88+
@arguments(last: $last, first: $first, after: $after, before: $before)
89+
}
90+
`
8891
const [viewer, refetch] = useRefetchableTodoAppDataFragment(props.frag)
8992
const [addTodo] = useTodoAppAddTodoMutation()
9093
const [setAppending] = useTodoAppSetAppendingMutation()

example-hooks-gen/ts/components/TodoList.tsx

+15-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ interface Props {
2525
viewer: TodoList$key
2626
}
2727

28+
graphql`
29+
mutation TodoListMarkAllTodosMutation($input: MarkAllTodosInput!) {
30+
markAllTodos(input: $input) {
31+
changedTodos {
32+
id
33+
complete
34+
}
35+
viewer {
36+
id
37+
completedCount
38+
}
39+
}
40+
}
41+
`
42+
2843
graphql`
2944
fragment TodoList on User
3045
@argumentDefinitions(
@@ -49,18 +64,6 @@ graphql`
4964
completedCount
5065
...TodoViewer
5166
}
52-
mutation TodoListMarkAllTodosMutation($input: MarkAllTodosInput!) {
53-
markAllTodos(input: $input) {
54-
changedTodos {
55-
id
56-
complete
57-
}
58-
viewer {
59-
id
60-
completedCount
61-
}
62-
}
63-
}
6467
`
6568

6669
const TodoList = (props: Props) => {

0 commit comments

Comments
 (0)