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

Commit 4666677

Browse files
committed
feat: initial pass at generated typed hooks
1 parent a190679 commit 4666677

30 files changed

+1003
-728
lines changed

example-hooks/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"scripts": {
44
"start": "babel-node ./server.js",
5-
"build": "relay-compiler --src ./ts/ --schema ./data/schema.graphql --language typescript --artifactDirectory ./ts/__relay_artifacts__",
5+
"build": "relay-compiler --src ./ts/ --schema ./data/schema.graphql --language typescript/hooks --artifactDirectory ./ts/__relay_artifacts__",
66
"update-schema": "babel-node ./scripts/updateSchema.js",
77
"lint": "tslint --project tsconfig.json",
88
"type-check": "tsc --noEmit --pretty"
@@ -18,9 +18,9 @@
1818
"graphql": "^15.3.0",
1919
"graphql-relay": "^0.6.0",
2020
"prop-types": "^15.6.2",
21-
"react": "0.0.0-experimental-f42431abe",
22-
"react-dom": "0.0.0-experimental-f42431abe",
23-
"react-relay": "^0.0.0-experimental-8058ef82",
21+
"react": "^17.0.1",
22+
"react-dom": "^17.0.1",
23+
"react-relay": "^11.0.0",
2424
"relay-runtime": "^10.0.1",
2525
"todomvc-app-css": "^2.1.0",
2626
"todomvc-common": "^1.0.3",
@@ -34,13 +34,13 @@
3434
"@types/prop-types": "^15.5.5",
3535
"@types/react": "^16.4.12",
3636
"@types/react-dom": "^16.0.7",
37-
"@types/react-relay": "^7.0.8",
38-
"@types/relay-runtime": "^10.0.1",
37+
"@types/react-relay": "^11.0.0",
38+
"@types/relay-runtime": "^10.1.10",
3939
"babel-cli": "^6.26.0",
4040
"babel-core": "^6.26.0",
4141
"babel-eslint": "6.1.2",
4242
"babel-loader": "^7.1.2",
43-
"babel-plugin-relay": "^10.0.1",
43+
"babel-plugin-relay": "^11.0.0",
4444
"babel-plugin-transform-runtime": "^6.12.0",
4545
"babel-preset-env": "^1.7.0",
4646
"babel-preset-react": "^6.11.1",
@@ -50,11 +50,11 @@
5050
"fork-ts-checker-webpack-plugin": "^3.1.1",
5151
"patch-package": "^6.2.0",
5252
"postinstall-postinstall": "^2.0.0",
53-
"relay-compiler": "^10.0.1",
53+
"relay-compiler": "^11.0.0",
5454
"relay-compiler-language-typescript": "file:../lib",
5555
"ts-loader": "^6.2.0",
5656
"tslint": "^5.20.0",
5757
"tslint-plugin-relay": "^0.0.3",
58-
"typescript": "^3.6.3"
58+
"typescript": "^3.9.9"
5959
}
6060
}

example-hooks/ts/__relay_artifacts__/AddTodoMutation.graphql.ts renamed to example-hooks/ts/__relay_artifacts__/TodoAppAddTodoMutation.graphql.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/* tslint:disable */
22
/* eslint-disable */
33

4-
import { ConcreteRequest } from "relay-runtime";
4+
import { ConcreteRequest, Disposable, IEnvironment, MutationConfig } from "relay-runtime";
5+
import { useMutation } from "react-relay";
6+
57
export type AddTodoInput = {
68
text: string;
79
clientMutationId?: string | null;
810
};
9-
export type AddTodoMutationVariables = {
11+
export type TodoAppAddTodoMutationVariables = {
1012
input: AddTodoInput;
1113
connections: Array<string>;
1214
append: boolean;
1315
};
14-
export type AddTodoMutationResponse = {
16+
export type TodoAppAddTodoMutationResponse = {
1517
readonly addTodo: {
1618
readonly todoEdge?: {
1719
readonly __typename: string;
@@ -28,15 +30,15 @@ export type AddTodoMutationResponse = {
2830
} | null;
2931
} | null;
3032
};
31-
export type AddTodoMutation = {
32-
readonly response: AddTodoMutationResponse;
33-
readonly variables: AddTodoMutationVariables;
33+
export type TodoAppAddTodoMutation = {
34+
readonly response: TodoAppAddTodoMutationResponse;
35+
readonly variables: TodoAppAddTodoMutationVariables;
3436
};
3537

3638

3739

3840
/*
39-
mutation AddTodoMutation(
41+
mutation TodoAppAddTodoMutation(
4042
$input: AddTodoInput!
4143
$append: Boolean! = true
4244
) {
@@ -186,7 +188,7 @@ return {
186188
],
187189
"kind": "Fragment",
188190
"metadata": null,
189-
"name": "AddTodoMutation",
191+
"name": "TodoAppAddTodoMutation",
190192
"selections": [
191193
{
192194
"alias": null,
@@ -224,7 +226,7 @@ return {
224226
(v0/*: any*/)
225227
],
226228
"kind": "Operation",
227-
"name": "AddTodoMutation",
229+
"name": "TodoAppAddTodoMutation",
228230
"selections": [
229231
{
230232
"alias": null,
@@ -277,14 +279,18 @@ return {
277279
]
278280
},
279281
"params": {
280-
"cacheID": "45b1c0dd3f77cf2030614e989ba1a0ae",
282+
"cacheID": "5ce6bcfd9fff5d1509633dea2ad0ef70",
281283
"id": null,
282284
"metadata": {},
283-
"name": "AddTodoMutation",
285+
"name": "TodoAppAddTodoMutation",
284286
"operationKind": "mutation",
285-
"text": "mutation AddTodoMutation(\n $input: AddTodoInput!\n $append: Boolean! = true\n) {\n addTodo(input: $input) {\n todoEdge @include(if: $append) {\n __typename\n cursor\n node {\n complete\n id\n text\n }\n }\n todoEdge @skip(if: $append) {\n __typename\n cursor\n node {\n complete\n id\n text\n }\n }\n viewer {\n id\n totalCount\n }\n }\n}\n"
287+
"text": "mutation TodoAppAddTodoMutation(\n $input: AddTodoInput!\n $append: Boolean! = true\n) {\n addTodo(input: $input) {\n todoEdge @include(if: $append) {\n __typename\n cursor\n node {\n complete\n id\n text\n }\n }\n todoEdge @skip(if: $append) {\n __typename\n cursor\n node {\n complete\n id\n text\n }\n }\n viewer {\n id\n totalCount\n }\n }\n}\n"
286288
}
287289
};
288290
})();
289-
(node as any).hash = '22b4d5cbe974f454b465ed39d335191e';
291+
(node as any).hash = '9fc424b62b7e322b67f3f1222bad0a76';
290292
export default node;
293+
294+
export const useTodoAppAddTodoMutation = (mutationConfig?: (environment: IEnvironment, config: MutationConfig<TodoAppAddTodoMutation>) => Disposable) => {
295+
return useMutation<TodoAppAddTodoMutation>(node, mutationConfig)
296+
}

example-hooks/ts/__relay_artifacts__/TodoApp_viewer.graphql.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/* eslint-disable */
33

44
import { ReaderFragment } from "relay-runtime";
5+
import { useFragment } from "react-relay";
6+
57
import { FragmentRefs } from "relay-runtime";
68
export type TodoApp_viewer = {
79
readonly id: string;
@@ -53,3 +55,12 @@ const node: ReaderFragment = {
5355
};
5456
(node as any).hash = 'b9743417c7b5ef2bbda96cf675aa9eb4';
5557
export default node;
58+
export function useTodoApp_viewerFragment<TKey extends TodoApp_viewer$key>(fragmentRef: TKey): Required<TKey>[" $data"]
59+
export function useTodoApp_viewerFragment<TKey extends TodoApp_viewer$key>(fragmentRef: TKey | null): Required<TKey>[" $data"] | null
60+
export function useTodoApp_viewerFragment<TKey extends TodoApp_viewer$key>(fragmentRef: ReadonlyArray<TKey>): ReadonlyArray<Required<TKey>[" $data"]>
61+
export function useTodoApp_viewerFragment<TKey extends TodoApp_viewer$key>(fragmentRef: ReadonlyArray<TKey | null>): ReadonlyArray<Required<TKey>[" $data"] | null>
62+
export function useTodoApp_viewerFragment<TKey extends TodoApp_viewer$key>(fragmentRef: ReadonlyArray<TKey> | null): ReadonlyArray<Required<TKey>[" $data"]> | null
63+
export function useTodoApp_viewerFragment<TKey extends TodoApp_viewer$key>(fragmentRef: ReadonlyArray<TKey | null> | null): ReadonlyArray<Required<TKey>[" $data"] | null> | null
64+
export function useTodoApp_viewerFragment(fragmentRef: any) {
65+
return useFragment(node, fragmentRef)
66+
}

example-hooks/ts/__relay_artifacts__/ChangeTodoStatusMutation.graphql.ts renamed to example-hooks/ts/__relay_artifacts__/TodoChangeStatusMutation.graphql.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/* tslint:disable */
22
/* eslint-disable */
33

4-
import { ConcreteRequest } from "relay-runtime";
4+
import { ConcreteRequest, Disposable, IEnvironment, MutationConfig } from "relay-runtime";
5+
import { useMutation } from "react-relay";
6+
57
export type ChangeTodoStatusInput = {
68
complete: boolean;
79
id: string;
810
clientMutationId?: string | null;
911
};
10-
export type ChangeTodoStatusMutationVariables = {
12+
export type TodoChangeStatusMutationVariables = {
1113
input: ChangeTodoStatusInput;
1214
};
13-
export type ChangeTodoStatusMutationResponse = {
15+
export type TodoChangeStatusMutationResponse = {
1416
readonly changeTodoStatus: {
1517
readonly todo: {
1618
readonly id: string;
@@ -22,15 +24,15 @@ export type ChangeTodoStatusMutationResponse = {
2224
} | null;
2325
} | null;
2426
};
25-
export type ChangeTodoStatusMutation = {
26-
readonly response: ChangeTodoStatusMutationResponse;
27-
readonly variables: ChangeTodoStatusMutationVariables;
27+
export type TodoChangeStatusMutation = {
28+
readonly response: TodoChangeStatusMutationResponse;
29+
readonly variables: TodoChangeStatusMutationVariables;
2830
};
2931

3032

3133

3234
/*
33-
mutation ChangeTodoStatusMutation(
35+
mutation TodoChangeStatusMutation(
3436
$input: ChangeTodoStatusInput!
3537
) {
3638
changeTodoStatus(input: $input) {
@@ -123,7 +125,7 @@ return {
123125
"argumentDefinitions": (v0/*: any*/),
124126
"kind": "Fragment",
125127
"metadata": null,
126-
"name": "ChangeTodoStatusMutation",
128+
"name": "TodoChangeStatusMutation",
127129
"selections": (v2/*: any*/),
128130
"type": "Mutation",
129131
"abstractKey": null
@@ -132,18 +134,22 @@ return {
132134
"operation": {
133135
"argumentDefinitions": (v0/*: any*/),
134136
"kind": "Operation",
135-
"name": "ChangeTodoStatusMutation",
137+
"name": "TodoChangeStatusMutation",
136138
"selections": (v2/*: any*/)
137139
},
138140
"params": {
139-
"cacheID": "add8723f75323848b2de0e56f1e9e0d7",
141+
"cacheID": "e499f8ec26332ab841d01a3c84722994",
140142
"id": null,
141143
"metadata": {},
142-
"name": "ChangeTodoStatusMutation",
144+
"name": "TodoChangeStatusMutation",
143145
"operationKind": "mutation",
144-
"text": "mutation ChangeTodoStatusMutation(\n $input: ChangeTodoStatusInput!\n) {\n changeTodoStatus(input: $input) {\n todo {\n id\n complete\n }\n viewer {\n id\n completedCount\n }\n }\n}\n"
146+
"text": "mutation TodoChangeStatusMutation(\n $input: ChangeTodoStatusInput!\n) {\n changeTodoStatus(input: $input) {\n todo {\n id\n complete\n }\n viewer {\n id\n completedCount\n }\n }\n}\n"
145147
}
146148
};
147149
})();
148-
(node as any).hash = '82df4993530f2c7019c4cb7382a187fa';
150+
(node as any).hash = '3a8a31fe58b7a5898515699f9a7415f8';
149151
export default node;
152+
153+
export const useTodoChangeStatusMutation = (mutationConfig?: (environment: IEnvironment, config: MutationConfig<TodoChangeStatusMutation>) => Disposable) => {
154+
return useMutation<TodoChangeStatusMutation>(node, mutationConfig)
155+
}

example-hooks/ts/__relay_artifacts__/RemoveCompletedTodosMutation.graphql.ts renamed to example-hooks/ts/__relay_artifacts__/TodoListFooterRemoveCompletedTodosMutation.graphql.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/* tslint:disable */
22
/* eslint-disable */
33

4-
import { ConcreteRequest } from "relay-runtime";
4+
import { ConcreteRequest, Disposable, IEnvironment, MutationConfig } from "relay-runtime";
5+
import { useMutation } from "react-relay";
6+
57
export type RemoveCompletedTodosInput = {
68
clientMutationId?: string | null;
79
};
8-
export type RemoveCompletedTodosMutationVariables = {
10+
export type TodoListFooterRemoveCompletedTodosMutationVariables = {
911
input: RemoveCompletedTodosInput;
1012
};
11-
export type RemoveCompletedTodosMutationResponse = {
13+
export type TodoListFooterRemoveCompletedTodosMutationResponse = {
1214
readonly removeCompletedTodos: {
1315
readonly deletedTodoIds: ReadonlyArray<string | null> | null;
1416
readonly viewer: {
@@ -17,15 +19,15 @@ export type RemoveCompletedTodosMutationResponse = {
1719
} | null;
1820
} | null;
1921
};
20-
export type RemoveCompletedTodosMutation = {
21-
readonly response: RemoveCompletedTodosMutationResponse;
22-
readonly variables: RemoveCompletedTodosMutationVariables;
22+
export type TodoListFooterRemoveCompletedTodosMutation = {
23+
readonly response: TodoListFooterRemoveCompletedTodosMutationResponse;
24+
readonly variables: TodoListFooterRemoveCompletedTodosMutationVariables;
2325
};
2426

2527

2628

2729
/*
28-
mutation RemoveCompletedTodosMutation(
30+
mutation TodoListFooterRemoveCompletedTodosMutation(
2931
$input: RemoveCompletedTodosInput!
3032
) {
3133
removeCompletedTodos(input: $input) {
@@ -80,7 +82,7 @@ return {
8082
"argumentDefinitions": (v0/*: any*/),
8183
"kind": "Fragment",
8284
"metadata": null,
83-
"name": "RemoveCompletedTodosMutation",
85+
"name": "TodoListFooterRemoveCompletedTodosMutation",
8486
"selections": [
8587
{
8688
"alias": null,
@@ -115,7 +117,7 @@ return {
115117
"operation": {
116118
"argumentDefinitions": (v0/*: any*/),
117119
"kind": "Operation",
118-
"name": "RemoveCompletedTodosMutation",
120+
"name": "TodoListFooterRemoveCompletedTodosMutation",
119121
"selections": [
120122
{
121123
"alias": null,
@@ -152,14 +154,18 @@ return {
152154
]
153155
},
154156
"params": {
155-
"cacheID": "4e579d172ceaf5d902f3da90438a1cfe",
157+
"cacheID": "5dedd68ce3bbac05fbc8735ff61c7194",
156158
"id": null,
157159
"metadata": {},
158-
"name": "RemoveCompletedTodosMutation",
160+
"name": "TodoListFooterRemoveCompletedTodosMutation",
159161
"operationKind": "mutation",
160-
"text": "mutation RemoveCompletedTodosMutation(\n $input: RemoveCompletedTodosInput!\n) {\n removeCompletedTodos(input: $input) {\n deletedTodoIds\n viewer {\n completedCount\n totalCount\n id\n }\n }\n}\n"
162+
"text": "mutation TodoListFooterRemoveCompletedTodosMutation(\n $input: RemoveCompletedTodosInput!\n) {\n removeCompletedTodos(input: $input) {\n deletedTodoIds\n viewer {\n completedCount\n totalCount\n id\n }\n }\n}\n"
161163
}
162164
};
163165
})();
164-
(node as any).hash = '303799d791e6e233861ee011ff3bdbb8';
166+
(node as any).hash = '42b0c614caae5e7751d06f9df258791c';
165167
export default node;
168+
169+
export const useTodoListFooterRemoveCompletedTodosMutation = (mutationConfig?: (environment: IEnvironment, config: MutationConfig<TodoListFooterRemoveCompletedTodosMutation>) => Disposable) => {
170+
return useMutation<TodoListFooterRemoveCompletedTodosMutation>(node, mutationConfig)
171+
}

example-hooks/ts/__relay_artifacts__/TodoListFooter_viewer.graphql.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/* eslint-disable */
33

44
import { ReaderFragment } from "relay-runtime";
5+
import { useFragment } from "react-relay";
6+
57
import { FragmentRefs } from "relay-runtime";
68
export type TodoListFooter_viewer = {
79
readonly id: string;
@@ -113,3 +115,12 @@ return {
113115
})();
114116
(node as any).hash = '2490c58e1768d71f3824c1facd127033';
115117
export default node;
118+
export function useTodoListFooter_viewerFragment<TKey extends TodoListFooter_viewer$key>(fragmentRef: TKey): Required<TKey>[" $data"]
119+
export function useTodoListFooter_viewerFragment<TKey extends TodoListFooter_viewer$key>(fragmentRef: TKey | null): Required<TKey>[" $data"] | null
120+
export function useTodoListFooter_viewerFragment<TKey extends TodoListFooter_viewer$key>(fragmentRef: ReadonlyArray<TKey>): ReadonlyArray<Required<TKey>[" $data"]>
121+
export function useTodoListFooter_viewerFragment<TKey extends TodoListFooter_viewer$key>(fragmentRef: ReadonlyArray<TKey | null>): ReadonlyArray<Required<TKey>[" $data"] | null>
122+
export function useTodoListFooter_viewerFragment<TKey extends TodoListFooter_viewer$key>(fragmentRef: ReadonlyArray<TKey> | null): ReadonlyArray<Required<TKey>[" $data"]> | null
123+
export function useTodoListFooter_viewerFragment<TKey extends TodoListFooter_viewer$key>(fragmentRef: ReadonlyArray<TKey | null> | null): ReadonlyArray<Required<TKey>[" $data"] | null> | null
124+
export function useTodoListFooter_viewerFragment(fragmentRef: any) {
125+
return useFragment(node, fragmentRef)
126+
}

0 commit comments

Comments
 (0)