File tree 2 files changed +109
-1
lines changed
2 files changed +109
-1
lines changed Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ function discoverTypes(
183
183
in order to get all the enums and input types that exist in this input type
184
184
*/
185
185
const inputType = getNamedType ( typeInfo . getInputType ( ) ) ;
186
- if ( inputType && isInputObjectType ( inputType ) ) {
186
+ if ( inputType && ( isInputObjectType ( inputType ) || isEnumType ( inputType ) ) ) {
187
187
collectTypesFromNode ( inputType , discoveredTypes ) ;
188
188
}
189
189
} ,
Original file line number Diff line number Diff line change @@ -762,6 +762,114 @@ describe('typescript-operation-types', () => {
762
762
` ) ;
763
763
} ) ;
764
764
765
+ it ( 'should include the input enum type when it is a variable' , async ( ) => {
766
+ const schema = buildSchema (
767
+ /* GraphQL */ `
768
+ type Mutation {
769
+ updateFoo(input: FooInput!, id: ID!): Foo
770
+ }
771
+
772
+ type Foo {
773
+ id: ID!
774
+ }
775
+
776
+ enum FooType {
777
+ FOO_A
778
+ FOO_B
779
+ FOO_C
780
+ }
781
+
782
+ enum BarType {
783
+ BAR_A
784
+ BAR_B
785
+ BAR_C
786
+ }
787
+
788
+ input FooInput {
789
+ fooType: FooType!
790
+ barInput: [BarInput]
791
+ count: Int
792
+ }
793
+
794
+ input BarInput {
795
+ bazInput: BazInput
796
+ barType: BarType!
797
+ }
798
+
799
+ input BazInput {
800
+ a: String
801
+ b: Int
802
+ }
803
+ ` ,
804
+ { assumeValid : true }
805
+ ) ;
806
+
807
+ const ast = parse ( /* GraphQL */ `
808
+ mutation MyMutation(
809
+ $id: ID!
810
+ $foo: FooType!
811
+ $bar: [BarInput]
812
+ $count: Int
813
+ ) {
814
+ updateFoo(
815
+ id: $id
816
+ input: { count: $count, fooType: $foo, barInput: $bar }
817
+ ) {
818
+ id
819
+ }
820
+ }
821
+ ` ) ;
822
+
823
+ const result = await plugin (
824
+ schema ,
825
+ [
826
+ {
827
+ document : ast ,
828
+ } ,
829
+ ] ,
830
+ { }
831
+ ) ;
832
+
833
+ expect ( result . content ) . toMatchInlineSnapshot ( `
834
+ "/** All built-in and custom scalars, mapped to their actual values */
835
+ export type Scalars = {
836
+ ID: string;
837
+ String: string;
838
+ Boolean: boolean;
839
+ Int: number;
840
+ Float: number;
841
+ };
842
+
843
+ export type Foo = {
844
+ __typename?: 'Foo';
845
+ id: Scalars['ID'];
846
+ };
847
+
848
+ export enum FooType {
849
+ FooA = 'FOO_A',
850
+ FooB = 'FOO_B',
851
+ FooC = 'FOO_C'
852
+ }
853
+
854
+ export enum BarType {
855
+ BarA = 'BAR_A',
856
+ BarB = 'BAR_B',
857
+ BarC = 'BAR_C'
858
+ }
859
+
860
+ export type BarInput = {
861
+ bazInput?: InputMaybe<BazInput>;
862
+ barType: BarType;
863
+ };
864
+
865
+ export type BazInput = {
866
+ a?: InputMaybe<Scalars['String']>;
867
+ b?: InputMaybe<Scalars['Int']>;
868
+ };
869
+ "
870
+ ` ) ;
871
+ } ) ;
872
+
765
873
describe ( 'when omitObjectTypes is true' , ( ) => {
766
874
it ( 'should include the fragment enums' , async ( ) => {
767
875
const ast = parse ( /* GraphQL */ `
You can’t perform that action at this time.
0 commit comments