@@ -7,7 +7,7 @@ use swc_common::{FileName, FilePathMapping, SourceMap};
77use swc_ecmascript:: ast:: {
88 BindingIdent , Decl , Expr , Module , ModuleItem , Stmt , TsArrayType , TsEntityName , TsFnParam ,
99 TsKeywordType , TsKeywordTypeKind , TsPropertySignature , TsType , TsTypeAnn , TsTypeElement ,
10- TsTypeLit , TsTypeParamInstantiation , TsTypeRef , TsUnionOrIntersectionType , TsUnionType ,
10+ TsTypeParamInstantiation , TsTypeRef , TsUnionOrIntersectionType , TsUnionType ,
1111} ;
1212use swc_ecmascript:: ast:: { Program , TsFnOrConstructorType , TsFnType } ;
1313
@@ -106,6 +106,12 @@ impl ParsedField {
106106 }
107107}
108108
109+ /// The main struct used for generating GraphQL schemas from a widened
110+ /// tsgql Typescript schema input.
111+ ///
112+ /// TODO: This code was written hastily and kind of confusing, should probably refactor
113+ /// it to use SWC's Visitor trait + state variables.
114+ /// Some good examples are in the Next.js [repo](https://github.com/vercel/next.js/tree/canary/packages/next/build/swc/src)
109115struct CodeGenCtx {
110116 schema : Schema ,
111117 manifest : HashMap < String , GraphQLKind > ,
@@ -361,7 +367,7 @@ impl CodeGenCtx {
361367 }
362368 } else {
363369 match type_params {
364- None => return Err ( anyhow:: anyhow!( "Missing type parameter for Promise" ) ) ,
370+ None => Err ( anyhow:: anyhow!( "Missing type parameter for Promise" ) ) ,
365371 Some ( TsTypeParamInstantiation { params, .. } ) => {
366372 match params. len ( ) {
367373 1 => { }
@@ -414,7 +420,7 @@ impl CodeGenCtx {
414420 None ,
415421 ) )
416422 }
417- _ => return self . parse_type ( "" , typ, false ) ,
423+ _ => self . parse_type ( "" , typ, false ) ,
418424 }
419425 }
420426 }
@@ -531,9 +537,6 @@ impl CodeGenCtx {
531537
532538 Ok ( ( ) )
533539 }
534- _ => {
535- panic ! ( "Cannot turn type literal into: {:?}" , kind) ;
536- }
537540 }
538541 }
539542
@@ -581,9 +584,9 @@ impl CodeGenCtx {
581584 }
582585 }
583586
584- /// Computes a name for a new Input type. The resulting name depends on the value of
585- /// `member_count `. If `member_count === 1`, then the return is simply a concatenation of
586- /// of `field_name` and the string "Input".
587+ /// Computes a name for a new Input type. The resulting name depends on the variant of
588+ /// `ComputeNameKind `. If it is `ComputeNameKind::Input` we try to generate a unique
589+ /// input name based on `field_name` and `param_name`
587590 ///
588591 /// Otherwise, we also concatenate the name of the param
589592 fn compute_new_name ( kind : ComputeNameKind , field_name : & str ) -> String {
0 commit comments