1
1
import {
2
2
Condition ,
3
+ createUserError ,
3
4
Fragment ,
4
- FragmentSpread ,
5
5
IRVisitor ,
6
6
LinkedField ,
7
7
Root ,
@@ -10,11 +10,7 @@ import {
10
10
TypeGenerator ,
11
11
TypeID
12
12
} from "relay-compiler" ;
13
- import {
14
- ConnectionField ,
15
- InlineFragment ,
16
- ModuleImport
17
- } from "relay-compiler/lib/core/GraphQLIR" ;
13
+ import { ConnectionField } from "relay-compiler/lib/core/GraphQLIR" ;
18
14
import { TypeGeneratorOptions } from "relay-compiler/lib/language/RelayLanguagePluginInterface" ;
19
15
import * as ConnectionFieldTransform from "relay-compiler/lib/transforms/ConnectionFieldTransform" ;
20
16
import * as FlattenTransform from "relay-compiler/lib/transforms/FlattenTransform" ;
@@ -28,13 +24,9 @@ import {
28
24
transformInputType ,
29
25
transformScalarType
30
26
} from "./TypeScriptTypeTransformers" ;
31
- // import { NodeVisitor } from "relay-compiler/lib/core/GraphQLIRVisitor";
32
27
33
28
// TODO: update typings and import properly
34
29
const { ConnectionInterface } = require ( "relay-runtime" ) ;
35
- const {
36
- createUserError
37
- } = require ( "relay-compiler/lib/core/RelayCompilerError" ) ;
38
30
39
31
type Selection = {
40
32
key : string ;
@@ -364,17 +356,17 @@ function importTypes(names: string[], fromModule: string): ts.Statement {
364
356
) ;
365
357
}
366
358
367
- // TODO: Add Connection to IRVisitor.NodeVisitor leave
368
359
function createVisitor (
369
360
schema : Schema ,
370
361
options : TypeGeneratorOptions
371
- ) : any /* IRVisitor.NodeVisitor */ {
362
+ ) : IRVisitor . NodeVisitor {
372
363
const state : State = {
373
364
customScalars : options . customScalars ,
374
365
enumsHasteModule : options . enumsHasteModule ,
375
366
existingFragmentNames : options . existingFragmentNames ,
376
367
generatedInputObjectTypes : { } ,
377
368
generatedFragments : new Set ( ) ,
369
+ hasConnectionResolver : false ,
378
370
optionalInputFields : options . optionalInputFields ,
379
371
usedEnums : { } ,
380
372
usedFragments : new Set ( ) ,
@@ -386,7 +378,7 @@ function createVisitor(
386
378
387
379
return {
388
380
leave : {
389
- Root ( node : Root ) {
381
+ Root ( node ) {
390
382
const inputVariablesType = generateInputVariablesType (
391
383
schema ,
392
384
node ,
@@ -468,7 +460,7 @@ function createVisitor(
468
460
return nodes ;
469
461
} ,
470
462
471
- Fragment ( node : Fragment ) {
463
+ Fragment ( node ) {
472
464
const flattenedSelections : Selection [ ] = flattenArray (
473
465
/* $FlowFixMe: selections have already been transformed */
474
466
( node . selections as any ) as ReadonlyArray < ReadonlyArray < Selection > >
@@ -519,7 +511,7 @@ function createVisitor(
519
511
exportType ( node . name , type )
520
512
] ;
521
513
} ,
522
- InlineFragment ( node : InlineFragment ) {
514
+ InlineFragment ( node ) {
523
515
return flattenArray (
524
516
/* $FlowFixMe: selections have already been transformed */
525
517
( node . selections as any ) as ReadonlyArray < ReadonlyArray < Selection > >
@@ -537,15 +529,15 @@ function createVisitor(
537
529
} ,
538
530
Condition : visitCondition ,
539
531
// TODO: Why not inline it like others?
540
- ScalarField ( node : any ) {
532
+ ScalarField ( node ) {
541
533
return visitScalarField ( schema , node , state ) ;
542
534
} ,
543
535
ConnectionField : visitLinkedField ,
544
536
LinkedField : visitLinkedField ,
545
- Connection ( node : any ) {
537
+ Connection ( node ) {
546
538
return visitConnection ( schema , node , state ) ;
547
539
} ,
548
- ModuleImport ( node : ModuleImport ) {
540
+ ModuleImport ( node ) {
549
541
return [
550
542
{
551
543
key : "__fragmentPropName" ,
@@ -563,7 +555,7 @@ function createVisitor(
563
555
}
564
556
] ;
565
557
} ,
566
- FragmentSpread ( node : FragmentSpread ) {
558
+ FragmentSpread ( node ) {
567
559
state . usedFragments . add ( node . name ) ;
568
560
return [
569
561
{
@@ -576,8 +568,7 @@ function createVisitor(
576
568
} ;
577
569
}
578
570
579
- // TODO: Add hasConnectionResolver to State
580
- function visitConnection ( schema : Schema , node : any , state : any ) {
571
+ function visitConnection ( schema : Schema , node : any , state : State ) {
581
572
const { EDGES } = ConnectionInterface . get ( ) ;
582
573
583
574
state . hasConnectionResolver = true ;
@@ -841,6 +832,9 @@ function createRawResponseTypeVisitor(
841
832
} ,
842
833
ConnectionField : visitLinkedField ,
843
834
LinkedField : visitLinkedField ,
835
+ Connection ( node ) {
836
+ return visitConnection ( schema , node , state ) ;
837
+ } ,
844
838
ClientExtension ( node ) {
845
839
return flattenArray (
846
840
/* $FlowFixMe: selections have already been transformed */
0 commit comments