@@ -12,12 +12,14 @@ import {
1212 visitWithTypeInfo ,
1313 getNamedType ,
1414 isInputObjectType ,
15+ isEnumType ,
1516 GraphQLInputObjectType ,
17+ GraphQLEnumType ,
1618 FragmentDefinitionNode ,
1719} from 'graphql' ;
1820import { createFieldNumberManager } from './operations/field-numbering.js' ;
1921import { buildMessageFromSelectionSet } from './operations/message-builder.js' ;
20- import { buildRequestMessage , buildInputObjectMessage } from './operations/request-builder.js' ;
22+ import { buildRequestMessage , buildInputObjectMessage , buildEnumType } from './operations/request-builder.js' ;
2123import { rootToProtoText } from './operations/proto-text-generator.js' ;
2224import {
2325 createRequestMessageName ,
@@ -99,8 +101,9 @@ class OperationsToProtoVisitor {
99101 // Proto AST root
100102 private readonly root : protobuf . Root ;
101103
102- // For tracking / avoiding duplicate messages
104+ // For tracking / avoiding duplicate messages and enums
103105 private createdMessages = new Set < string > ( ) ;
106+ private createdEnums = new Set < string > ( ) ;
104107
105108 // Lock manager for field number stability
106109 private readonly lockManager : ProtoLockManager ;
@@ -211,6 +214,7 @@ class OperationsToProtoVisitor {
211214 fieldNumberManager : this . fieldNumberManager ,
212215 fragments : this . fragments ,
213216 schema : this . schema ,
217+ createdEnums : this . createdEnums ,
214218 } ,
215219 ) ;
216220
@@ -249,7 +253,7 @@ class OperationsToProtoVisitor {
249253 }
250254
251255 /**
252- * Process input object types referenced in a type node
256+ * Process input object types and enums referenced in a type node
253257 */
254258 private processInputObjectTypes ( typeNode : any ) : void {
255259 // Handle NonNullType and ListType wrappers
@@ -273,19 +277,39 @@ class OperationsToProtoVisitor {
273277 this . root . add ( inputMessage ) ;
274278 this . createdMessages . add ( typeName ) ;
275279
276- // Recursively process nested input objects
280+ // Recursively process nested input objects and enums
277281 const fields = ( type as GraphQLInputObjectType ) . getFields ( ) ;
278282 for ( const field of Object . values ( fields ) ) {
279283 const fieldType = getNamedType ( field . type ) ;
280284 if ( isInputObjectType ( fieldType ) ) {
281285 this . processInputObjectTypes ( { kind : 'NamedType' , name : { value : fieldType . name } } ) ;
286+ } else if ( isEnumType ( fieldType ) ) {
287+ this . processEnumType ( fieldType as GraphQLEnumType ) ;
282288 }
283289 }
284290 }
291+ } else if ( type && isEnumType ( type ) ) {
292+ // Create enum type if not already created
293+ this . processEnumType ( type as GraphQLEnumType ) ;
285294 }
286295 }
287296 }
288297
298+ /**
299+ * Process and add an enum type to the proto root
300+ */
301+ private processEnumType ( enumType : GraphQLEnumType ) : void {
302+ const typeName = enumType . name ;
303+
304+ if ( ! this . createdEnums . has ( typeName ) ) {
305+ const protoEnum = buildEnumType ( enumType , {
306+ includeComments : this . includeComments ,
307+ } ) ;
308+ this . root . add ( protoEnum ) ;
309+ this . createdEnums . add ( typeName ) ;
310+ }
311+ }
312+
289313 /**
290314 * Helper: Get root operation type
291315 */
0 commit comments