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

Commit ea35fd5

Browse files
committed
[generator] Add support for @match directive.
Fixes #113
1 parent 22ec196 commit ea35fd5

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

src/TypeScriptGenerator.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "relay-compiler";
1010
import * as RelayCompilerPublic from "relay-compiler";
1111

12-
import { GraphQLNonNull } from "graphql";
12+
import { GraphQLNonNull, GraphQLString } from "graphql";
1313
import * as ts from "typescript";
1414

1515
import {
@@ -424,6 +424,24 @@ function createVisitor(options: TypeGeneratorOptions) {
424424
}
425425
];
426426
},
427+
ModuleImport(node: any) {
428+
return [
429+
{
430+
key: "__fragmentPropName",
431+
conditional: true,
432+
value: transformScalarType(GraphQLString, state)
433+
},
434+
{
435+
key: "__module_component",
436+
conditional: true,
437+
value: transformScalarType(GraphQLString, state)
438+
},
439+
{
440+
key: "__fragments_" + node.name,
441+
ref: node.name
442+
}
443+
];
444+
},
427445
FragmentSpread(node: any) {
428446
state.usedFragments.add(node.name);
429447
return [

test/__snapshots__/TypeScriptGenerator-test.ts.snap

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,15 @@ export type NameRendererFragment$ref = typeof _NameRendererFragment$ref;
372372
export type NameRendererFragment = {
373373
readonly id: string;
374374
readonly nameRenderer: ({
375-
readonly __module_component?: any | null;
375+
readonly __fragmentPropName?: string | null;
376+
readonly __module_component?: string | null;
377+
readonly " $fragmentRefs": PlainUserNameRenderer_name$ref & MarkdownUserNameRenderer_name$ref;
376378
} & ({
377-
readonly __module_component: any | null;
379+
readonly __fragmentPropName?: string | null;
380+
readonly __module_component: string | null;
381+
readonly " $fragmentRefs": PlainUserNameRenderer_name$ref;
382+
} | {
383+
readonly " $fragmentRefs": MarkdownUserNameRenderer_name$ref;
378384
} | {
379385
/*This will never be '% other', but we need some
380386
value in case none of the concrete values match.*/
@@ -441,9 +447,15 @@ export type NameRendererQueryVariables = {
441447
export type NameRendererQueryResponse = {
442448
readonly me: {
443449
readonly nameRenderer: ({
444-
readonly __module_component?: any | null;
450+
readonly __fragmentPropName?: string | null;
451+
readonly __module_component?: string | null;
452+
readonly " $fragmentRefs": PlainUserNameRenderer_name$ref & MarkdownUserNameRenderer_name$ref;
445453
} & ({
446-
readonly __module_component: any | null;
454+
readonly __fragmentPropName?: string | null;
455+
readonly __module_component: string | null;
456+
readonly " $fragmentRefs": PlainUserNameRenderer_name$ref;
457+
} | {
458+
readonly " $fragmentRefs": MarkdownUserNameRenderer_name$ref;
447459
} | {
448460
/*This will never be '% other', but we need some
449461
value in case none of the concrete values match.*/
@@ -1514,9 +1526,15 @@ export type NameRendererFragment$ref = any;
15141526
export type NameRendererFragment = {
15151527
readonly id: string;
15161528
readonly nameRenderer: ({
1517-
readonly __module_component?: any | null;
1529+
readonly __fragmentPropName?: string | null;
1530+
readonly __module_component?: string | null;
1531+
readonly " $fragmentRefs": PlainUserNameRenderer_name$ref & MarkdownUserNameRenderer_name$ref;
15181532
} & ({
1519-
readonly __module_component: any | null;
1533+
readonly __fragmentPropName?: string | null;
1534+
readonly __module_component: string | null;
1535+
readonly " $fragmentRefs": PlainUserNameRenderer_name$ref;
1536+
} | {
1537+
readonly " $fragmentRefs": MarkdownUserNameRenderer_name$ref;
15201538
} | {
15211539
/*This will never be '% other', but we need some
15221540
value in case none of the concrete values match.*/
@@ -1581,9 +1599,15 @@ export type NameRendererQueryVariables = {
15811599
export type NameRendererQueryResponse = {
15821600
readonly me: {
15831601
readonly nameRenderer: ({
1584-
readonly __module_component?: any | null;
1602+
readonly __fragmentPropName?: string | null;
1603+
readonly __module_component?: string | null;
1604+
readonly " $fragmentRefs": PlainUserNameRenderer_name$ref & MarkdownUserNameRenderer_name$ref;
15851605
} & ({
1586-
readonly __module_component: any | null;
1606+
readonly __fragmentPropName?: string | null;
1607+
readonly __module_component: string | null;
1608+
readonly " $fragmentRefs": PlainUserNameRenderer_name$ref;
1609+
} | {
1610+
readonly " $fragmentRefs": MarkdownUserNameRenderer_name$ref;
15871611
} | {
15881612
/*This will never be '% other', but we need some
15891613
value in case none of the concrete values match.*/

0 commit comments

Comments
 (0)