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

Commit 2166205

Browse files
committed
feat(test): update typescript generator test to match flow
1 parent 9c9afb6 commit 2166205

File tree

2 files changed

+84
-23
lines changed

2 files changed

+84
-23
lines changed

test/TypeScriptGenerator-test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,43 @@ function generate(text, options) {
1010
const schema = transformASTSchema(RelayTestSchema, [
1111
IRTransforms.schemaExtensions[1], // RelayMatchTransform.SCHEMA_EXTENSION,
1212
IRTransforms.schemaExtensions[2], // RelayRelayDirectiveTransform.SCHEMA_EXTENSION,
13+
`
14+
scalar Color
15+
extend type User {
16+
color: Color
17+
}
18+
type ExtraUser implements Actor {
19+
address: StreetAddress
20+
allPhones: [Phone]
21+
birthdate: Date
22+
emailAddresses: [String]
23+
firstName(if: Boolean, unless: Boolean): String
24+
friends(after: ID, before: ID, first: Int, last: Int, orderby: [String], find: String, isViewerFriend: Boolean, if: Boolean, unless: Boolean, traits: [PersonalityTraits]): FriendsConnection
25+
hometown: Page
26+
id: ID!
27+
lastName: String
28+
name: String
29+
nameRenderer(supported: [String!]!): UserNameRenderer
30+
nameRenderable(supported: [String!]!): UserNameRenderable
31+
profilePicture(size: [Int], preset: PhotoSize): Image
32+
screennames: [Screenname]
33+
subscribeStatus: String
34+
subscribers(first: Int): SubscribersConnection
35+
url(relative: Boolean, site: String): String
36+
websites: [String]
37+
username: String
38+
}
39+
`,
1340
]);
1441
const {definitions} = parseGraphQLText(schema, text);
1542
return new GraphQLCompilerContext(RelayTestSchema, schema)
1643
.addAll(definitions)
1744
.applyTransforms(TypeScriptGenerator.transforms)
1845
.documents()
19-
.map(doc => TypeScriptGenerator.generate(doc, options))
46+
.map(doc => TypeScriptGenerator.generate(doc, {
47+
...options,
48+
schema,
49+
}))
2050
.join('\n\n');
2151
}
2252

test/__snapshots__/TypeScriptGenerator-test.ts.snap

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -811,17 +811,33 @@ fragment TypenameInsideWithOverlappingFieldsFull on Viewer {
811811
}
812812
813813
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
814-
THROWN EXCEPTION:
815-
816-
Error: RelayParser: Encountered 1 error(s):
817-
- Unknown type: 'ExtraUser'.
818-
819-
GraphQL request (15:12)
820-
14: }
821-
15: ... on ExtraUser {
822-
^
823-
16: id
824-
814+
declare const _TypenameInsideWithOverlappingFieldsFull$ref: unique symbol;
815+
export type TypenameInsideWithOverlappingFieldsFull$ref = typeof _TypenameInsideWithOverlappingFieldsFull$ref;
816+
export type TypenameInsideWithOverlappingFieldsFull = {
817+
readonly actor: ({
818+
readonly __typename: string;
819+
readonly id?: string;
820+
readonly name?: string | null;
821+
readonly profile_picture?: {
822+
readonly uri: string | null;
823+
} | null;
824+
} & ({
825+
readonly __typename: "Page";
826+
readonly id: string;
827+
readonly name: string | null;
828+
} | {
829+
readonly __typename: "User";
830+
readonly profile_picture: {
831+
readonly uri: string | null;
832+
} | null;
833+
} | {
834+
/*This will never be '% other', but we need some
835+
value in case none of the concrete values match.*/
836+
readonly __typename: "%other";
837+
})) | null;
838+
readonly " $refType": TypenameInsideWithOverlappingFieldsFull$ref;
839+
};
840+
825841
`;
826842
827843
exports[`TypeScriptGenerator with a single artifact directory matches expected output: typename-on-union.graphql 1`] = `
@@ -1928,17 +1944,32 @@ fragment TypenameInsideWithOverlappingFieldsFull on Viewer {
19281944
}
19291945
19301946
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
1931-
THROWN EXCEPTION:
1932-
1933-
Error: RelayParser: Encountered 1 error(s):
1934-
- Unknown type: 'ExtraUser'.
1935-
1936-
GraphQL request (15:12)
1937-
14: }
1938-
15: ... on ExtraUser {
1939-
^
1940-
16: id
1941-
1947+
export type TypenameInsideWithOverlappingFieldsFull$ref = any;
1948+
export type TypenameInsideWithOverlappingFieldsFull = {
1949+
readonly actor: ({
1950+
readonly __typename: string;
1951+
readonly id?: string;
1952+
readonly name?: string | null;
1953+
readonly profile_picture?: {
1954+
readonly uri: string | null;
1955+
} | null;
1956+
} & ({
1957+
readonly __typename: "Page";
1958+
readonly id: string;
1959+
readonly name: string | null;
1960+
} | {
1961+
readonly __typename: "User";
1962+
readonly profile_picture: {
1963+
readonly uri: string | null;
1964+
} | null;
1965+
} | {
1966+
/*This will never be '% other', but we need some
1967+
value in case none of the concrete values match.*/
1968+
readonly __typename: "%other";
1969+
})) | null;
1970+
readonly " $refType": TypenameInsideWithOverlappingFieldsFull$ref;
1971+
};
1972+
19421973
`;
19431974
19441975
exports[`TypeScriptGenerator without a single artifact directory matches expected output: typename-on-union.graphql 1`] = `

0 commit comments

Comments
 (0)