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

Commit f189e95

Browse files
committed
feat: add FragmentRefs import
1 parent 72a2eb0 commit f189e95

File tree

6 files changed

+120
-38
lines changed

6 files changed

+120
-38
lines changed

example/ts/__relay_artifacts__/TodoListFooter_viewer.graphql.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* tslint:disable */
22

33
import { ReaderFragment } from "relay-runtime";
4+
import { FragmentRefs } from "relay-runtime";
45
export type TodoListFooter_viewer = {
56
readonly id: string;
67
readonly completedCount: number | null;

example/ts/__relay_artifacts__/Todo_todo.graphql.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* tslint:disable */
22

33
import { ReaderFragment } from "relay-runtime";
4+
import { FragmentRefs } from "relay-runtime";
45
export type Todo_todo = {
56
readonly complete: boolean | null;
67
readonly id: string;
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
/* tslint:disable */
22

3-
import { ReaderFragment } from "relay-runtime"
3+
import { ReaderFragment } from "relay-runtime";
4+
import { FragmentRefs } from "relay-runtime";
45
export type Todo_viewer = {
5-
readonly id: string
6-
readonly totalCount: number | null
7-
readonly completedCount: number | null
8-
readonly " $refType": "Todo_viewer"
9-
}
10-
export type Todo_viewer$data = Todo_viewer
6+
readonly id: string;
7+
readonly totalCount: number | null;
8+
readonly completedCount: number | null;
9+
readonly " $refType": "Todo_viewer";
10+
};
11+
export type Todo_viewer$data = Todo_viewer;
1112
export type Todo_viewer$key = {
12-
readonly " $data"?: Todo_viewer$data
13-
readonly " $fragmentRefs": FragmentRefs<"Todo_viewer">
14-
}
13+
readonly " $data"?: Todo_viewer$data;
14+
readonly " $fragmentRefs": FragmentRefs<"Todo_viewer">;
15+
};
16+
17+
1518

1619
const node: ReaderFragment = {
17-
kind: "Fragment",
18-
name: "Todo_viewer",
19-
type: "User",
20-
metadata: null,
21-
argumentDefinitions: [],
22-
selections: [
20+
"kind": "Fragment",
21+
"name": "Todo_viewer",
22+
"type": "User",
23+
"metadata": null,
24+
"argumentDefinitions": [],
25+
"selections": [
2326
{
24-
kind: "ScalarField",
25-
alias: null,
26-
name: "id",
27-
args: null,
28-
storageKey: null,
27+
"kind": "ScalarField",
28+
"alias": null,
29+
"name": "id",
30+
"args": null,
31+
"storageKey": null
2932
},
3033
{
31-
kind: "ScalarField",
32-
alias: null,
33-
name: "totalCount",
34-
args: null,
35-
storageKey: null,
34+
"kind": "ScalarField",
35+
"alias": null,
36+
"name": "totalCount",
37+
"args": null,
38+
"storageKey": null
3639
},
3740
{
38-
kind: "ScalarField",
39-
alias: null,
40-
name: "completedCount",
41-
args: null,
42-
storageKey: null,
43-
},
44-
],
45-
}
46-
;(node as any).hash = "1e2b17bb7b92d4521c4e72309d996339"
47-
export default node
41+
"kind": "ScalarField",
42+
"alias": null,
43+
"name": "completedCount",
44+
"args": null,
45+
"storageKey": null
46+
}
47+
]
48+
};
49+
(node as any).hash = '1e2b17bb7b92d4521c4e72309d996339';
50+
export default node;

src/TypeScriptGenerator.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ function createVisitor(options: TypeGeneratorOptions): IRVisitor.NodeVisitor {
334334
useHaste: options.useHaste,
335335
useSingleArtifactDirectory: options.useSingleArtifactDirectory,
336336
noFutureProofEnums: options.noFutureProofEnums,
337-
matchFields: new Map()
337+
matchFields: new Map(),
338+
runtimeImports: new Set()
338339
};
339340

340341
return {
@@ -466,10 +467,11 @@ function createVisitor(options: TypeGeneratorOptions): IRVisitor.NodeVisitor {
466467
baseType
467468
])
468469
: baseType;
470+
state.runtimeImports.add("FragmentRefs");
469471

470472
return [
471-
...getFragmentRefsTypeImport(state),
472473
...getEnumDefinitions(state),
474+
importTypes(Array.from(state.runtimeImports).sort(), "relay-runtime"),
473475
exportType(node.name, type),
474476
exportType(dataTypeName, dataType),
475477
exportType(

src/TypeScriptTypeTransformers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type State = {
2525
};
2626
generatedFragments: Set<string>;
2727
matchFields: Map<string, ts.TypeNode>;
28+
runtimeImports: Set<string>;
2829
} & TypeGeneratorOptions;
2930

3031
function getInputObjectTypeIdentifier(type: GraphQLInputObjectType): string {

0 commit comments

Comments
 (0)