@@ -597,6 +597,7 @@ class GArgs<T extends AnyType, X extends Args> extends Type<T, 'Args'> {
597
597
598
598
export class GarphSchema {
599
599
types : AnyType [ ] = [ ]
600
+
600
601
nodeType = this . interface ( 'Node' , {
601
602
id : this . id ( )
602
603
} )
@@ -615,19 +616,29 @@ export class GarphSchema {
615
616
after : this . id ( ) . optional ( )
616
617
}
617
618
619
+ registerType ( type : AnyType ) {
620
+ const name = type . typeDef . name
621
+ if ( name ) {
622
+ if ( this . types . find ( t => t . typeDef . name === name ) ) {
623
+ throw new Error ( `Detected multiple types with name: ${ name } ` )
624
+ }
625
+ }
626
+ this . types . push ( type )
627
+ }
628
+
618
629
constructor ( { types } : { types : AnyType [ ] } = { types : [ ] } ) {
619
- this . types . push ( ... types )
630
+ types . forEach ( t => this . registerType ( t ) )
620
631
}
621
632
622
633
type < N extends string , T extends AnyTypes > ( name : N , shape : T ) {
623
634
const t = new GType < N , T > ( name , shape )
624
- this . types . push ( t )
635
+ this . registerType ( t )
625
636
return t
626
637
}
627
638
628
639
node < N extends string , T extends AnyTypes > ( name : N , shape : T ) {
629
640
const t = new GType < N , T > ( name , shape ) . implements ( this . nodeType )
630
- this . types . push ( t )
641
+ this . registerType ( t )
631
642
return t
632
643
}
633
644
@@ -637,7 +648,7 @@ export class GarphSchema {
637
648
pageInfo : this . pageInfoType
638
649
} )
639
650
640
- this . types . push ( t )
651
+ this . registerType ( t )
641
652
return t
642
653
}
643
654
@@ -650,37 +661,37 @@ export class GarphSchema {
650
661
cursor : g . string ( )
651
662
} )
652
663
653
- this . types . push ( t )
664
+ this . registerType ( t )
654
665
return t
655
666
}
656
667
657
668
inputType < N extends string , T extends AnyTypes > ( name : N , shape : T ) {
658
669
const t = new GInput < N , T > ( name , shape )
659
- this . types . push ( t )
670
+ this . registerType ( t )
660
671
return t
661
672
}
662
673
663
674
enumType < N extends string , T extends readonly string [ ] | TSEnumType > ( name : N , args : T ) {
664
675
const t = new GEnum < N , T > ( name , args )
665
- this . types . push ( t )
676
+ this . registerType ( t )
666
677
return t
667
678
}
668
679
669
680
unionType < N extends string , T extends AnyObjects > ( name : N , args : T ) {
670
681
const t = new GUnion < N , T > ( name , args )
671
- this . types . push ( t )
682
+ this . registerType ( t )
672
683
return t
673
684
}
674
685
675
686
scalarType < I , O > ( name : string , options ?: ScalarOptions < I , O > ) {
676
687
const t = new GScalar < I , O > ( name , options )
677
- this . types . push ( t )
688
+ this . registerType ( t )
678
689
return t
679
690
}
680
691
681
692
interface < N extends string , T extends AnyTypes > ( name : N , shape : T ) {
682
693
const t = new GInterface < N , T > ( name , shape )
683
- this . types . push ( t )
694
+ this . registerType ( t )
684
695
return t
685
696
}
686
697
0 commit comments