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

Commit 376bf95

Browse files
alloykastermester
authored andcommitted
[TypeGenerator] Disable fragment imports for now.
1 parent ac7ba3d commit 376bf95

File tree

3 files changed

+143
-7
lines changed

3 files changed

+143
-7
lines changed

src/TypeScriptGenerator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,11 @@ function groupRefs(props: Selection[]): Selection[] {
467467
function getFragmentImports(state: State) {
468468
const imports: ts.Statement[] = [];
469469
if (state.usedFragments.size > 0) {
470-
const ownDirectory = state.destinationDirectory.getPath("");
470+
const ownDirectory = state.destinationDirectory && state.destinationDirectory.getPath("");
471471
const usedFragments = Array.from(state.usedFragments).sort();
472472
for (const usedFragment of usedFragments) {
473473
const refTypeName = getRefTypeName(usedFragment);
474-
if (state.existingFragmentNames.has(usedFragment)) {
474+
if (ownDirectory && state.getGeneratedDirectory && state.existingFragmentNames.has(usedFragment)) {
475475
const importDir = state.getGeneratedDirectory(usedFragment).getPath("");
476476
const relative = path.relative(ownDirectory, importDir);
477477
const relativeReference = relative.length === 0 ? "./" : "";

src/TypeScriptTypeTransformers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ export type ScalarTypeMapping = {
2020
export interface Options {
2121
customScalars: ScalarTypeMapping;
2222
useHaste: boolean;
23-
getGeneratedDirectory: (name: string) => CodegenDirectory;
24-
destinationDirectory: CodegenDirectory;
2523
enumsHasteModule: string | null | undefined;
2624
existingFragmentNames: Set<string>;
2725
inputFieldWhiteList: ReadonlyArray<string>;
2826
relayRuntimeModule: string;
27+
// TODO: Marking these as optional until we determine how we can best make imports work.
28+
getGeneratedDirectory?: (name: string) => CodegenDirectory;
29+
destinationDirectory?: CodegenDirectory;
2930
}
3031

3132
export type State = {

test/__snapshots__/TypeScriptGenerator-test.ts.snap

Lines changed: 138 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,43 @@ fragment ConcreateTypes on Viewer {
6464
}
6565
6666
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
67-
TODO
67+
import { FragmentReference } from "relay-runtime";
68+
export enum FragmentSpread_ref {
69+
}
70+
export type FragmentSpread = {
71+
readonly id: string;
72+
readonly justFrag: ({
73+
readonly " $fragments": PictureFragment_ref;
74+
}) | null;
75+
readonly fragAndField: ({
76+
readonly uri: string | null;
77+
readonly " $fragments": PictureFragment_ref;
78+
}) | null;
79+
readonly " $fragments": OtherFragment_ref & UserFrag1_ref & UserFrag2_ref;
80+
readonly " $refType": FragmentSpread_ref;
81+
};
82+
83+
84+
import { FragmentReference } from "relay-runtime";
85+
export enum ConcreateTypes_ref {
86+
}
87+
export type ConcreateTypes = {
88+
readonly actor: ({
89+
readonly __typename: "Page";
90+
readonly id: string;
91+
readonly " $fragments": PageFragment_ref;
92+
} | {
93+
readonly __typename: "User";
94+
readonly name: string | null;
95+
} | {
96+
/*This will never be '% other', but we need some
97+
value in case none of the concrete values match.*/
98+
readonly __typename: "%other";
99+
}) | null;
100+
readonly " $refType": ConcreateTypes_ref;
101+
};
102+
103+
`;
68104

69105
exports[`TypeScriptGenerator matches expected output: inline-fragment.graphql 1`] = `
70106
~~~~~~~~~~ INPUT ~~~~~~~~~~
@@ -130,7 +166,63 @@ fragment InlineFragmentKitchenSink on Story {
130166
}
131167
132168
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
133-
TODO
169+
import { FragmentReference } from "relay-runtime";
170+
export enum InlineFragment_ref {
171+
}
172+
export type InlineFragment = {
173+
readonly id: string;
174+
readonly name?: string | null;
175+
readonly message?: ({
176+
readonly text: string | null;
177+
}) | null;
178+
readonly " $refType": InlineFragment_ref;
179+
};
180+
181+
182+
import { FragmentReference } from "relay-runtime";
183+
export enum InlineFragmentWithOverlappingFields_ref {
184+
}
185+
export type InlineFragmentWithOverlappingFields = {
186+
readonly hometown?: ({
187+
readonly id: string;
188+
readonly name: string | null;
189+
readonly message?: ({
190+
readonly text: string | null;
191+
}) | null;
192+
}) | null;
193+
readonly name?: string | null;
194+
readonly " $refType": InlineFragmentWithOverlappingFields_ref;
195+
};
196+
197+
198+
import { FragmentReference } from "relay-runtime";
199+
export enum InlineFragmentConditionalID_ref {
200+
}
201+
export type InlineFragmentConditionalID = {
202+
readonly id?: string;
203+
readonly name?: string | null;
204+
readonly " $refType": InlineFragmentConditionalID_ref;
205+
};
206+
207+
208+
import { FragmentReference } from "relay-runtime";
209+
export enum InlineFragmentKitchenSink_ref {
210+
}
211+
export type InlineFragmentKitchenSink = {
212+
readonly actor: ({
213+
readonly id: string;
214+
readonly profilePicture: ({
215+
readonly uri: string | null;
216+
readonly width?: number | null;
217+
readonly height?: number | null;
218+
}) | null;
219+
readonly name?: string | null;
220+
readonly " $fragments": SomeFragment_ref;
221+
}) | null;
222+
readonly " $refType": InlineFragmentKitchenSink_ref;
223+
};
224+
225+
`;
134226

135227
exports[`TypeScriptGenerator matches expected output: linked-field.graphql 1`] = `
136228
~~~~~~~~~~ INPUT ~~~~~~~~~~
@@ -583,4 +675,47 @@ fragment AnotherRecursiveFragment on Image {
583675
}
584676
585677
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
586-
TODO
678+
import { FragmentReference } from "relay-runtime";
679+
export enum UserProfile_ref {
680+
}
681+
export type UserProfile = {
682+
readonly profilePicture: ({
683+
readonly uri: string | null;
684+
readonly width: number | null;
685+
readonly height: number | null;
686+
readonly " $fragments": PhotoFragment_ref;
687+
}) | null;
688+
readonly " $refType": UserProfile_ref;
689+
};
690+
691+
692+
import { FragmentReference } from "relay-runtime";
693+
export enum PhotoFragment_ref {
694+
}
695+
export type PhotoFragment = {
696+
readonly uri: string | null;
697+
readonly width: number | null;
698+
readonly " $refType": PhotoFragment_ref;
699+
};
700+
701+
702+
import { FragmentReference } from "relay-runtime";
703+
export enum RecursiveFragment_ref {
704+
}
705+
export type RecursiveFragment = {
706+
readonly uri: string | null;
707+
readonly width: number | null;
708+
readonly " $refType": RecursiveFragment_ref;
709+
};
710+
711+
712+
import { FragmentReference } from "relay-runtime";
713+
export enum AnotherRecursiveFragment_ref {
714+
}
715+
export type AnotherRecursiveFragment = {
716+
readonly uri: string | null;
717+
readonly height: number | null;
718+
readonly " $refType": AnotherRecursiveFragment_ref;
719+
};
720+
721+
`;

0 commit comments

Comments
 (0)