@@ -46,7 +46,6 @@ import {
4646} from 'graphql' ;
4747import { TypeScriptDocumentsPluginConfig } from './config.js' ;
4848import { TypeScriptOperationVariablesToObject , SCALARS } from './ts-operation-variables-to-object.js' ;
49- import { TypeScriptSelectionSetProcessor } from './ts-selection-set-processor.js' ;
5049
5150export interface TypeScriptDocumentsParsedConfig extends ParsedDocumentsConfig {
5251 arrayInputCoercion : boolean ;
@@ -88,7 +87,6 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
8887 avoidOptionals : normalizeAvoidOptionals ( getConfigValue ( config . avoidOptionals , false ) ) ,
8988 immutableTypes : getConfigValue ( config . immutableTypes , false ) ,
9089 nonOptionalTypename : getConfigValue ( config . nonOptionalTypename , false ) ,
91- preResolveTypes : getConfigValue ( config . preResolveTypes , true ) ,
9290 mergeFragmentTypes : getConfigValue ( config . mergeFragmentTypes , false ) ,
9391 allowUndefinedQueryVariables : getConfigValue ( config . allowUndefinedQueryVariables , false ) ,
9492 enumType : getConfigValue ( config . enumType , 'string-literal' ) ,
@@ -105,22 +103,9 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
105103 this . _outputPath = outputPath ;
106104 autoBind ( this ) ;
107105
108- const preResolveTypes = getConfigValue ( config . preResolveTypes , true ) ;
109106 const defaultMaybeValue = 'T | null' ;
110107 const maybeValue = getConfigValue ( config . maybeValue , defaultMaybeValue ) ;
111108
112- const wrapOptional = ( type : string ) => {
113- if ( preResolveTypes === true ) {
114- return maybeValue . replace ( 'T' , type ) ;
115- }
116- const prefix = this . config . namespacedImportName ? `${ this . config . namespacedImportName } .` : '' ;
117- return `${ prefix } Maybe<${ type } >` ;
118- } ;
119- const wrapArray = ( type : string ) => {
120- const listModifier = this . config . immutableTypes ? 'ReadonlyArray' : 'Array' ;
121- return `${ listModifier } <${ type } >` ;
122- } ;
123-
124109 const allFragments : LoadedFragment [ ] = [
125110 ...( documentNode . definitions . filter ( d => d . kind === Kind . FRAGMENT_DEFINITION ) as FragmentDefinitionNode [ ] ) . map (
126111 fragmentDef => ( {
@@ -144,14 +129,18 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
144129 formatNamedField : ( { name, isOptional } ) => {
145130 return ( this . config . immutableTypes ? `readonly ${ name } ` : name ) + ( isOptional ? '?' : '' ) ;
146131 } ,
147- wrapTypeWithModifiers ( baseType , type ) {
148- return wrapTypeWithModifiers ( baseType , type , { wrapOptional, wrapArray } ) ;
132+ wrapTypeWithModifiers : ( baseType , type ) => {
133+ return wrapTypeWithModifiers ( baseType , type , {
134+ wrapOptional : type => maybeValue . replace ( 'T' , type ) ,
135+ wrapArray : type => {
136+ const listModifier = this . config . immutableTypes ? 'ReadonlyArray' : 'Array' ;
137+ return `${ listModifier } <${ type } >` ;
138+ } ,
139+ } ) ;
149140 } ,
150141 printFieldsOnNewLines : this . config . printFieldsOnNewLines ,
151142 } ;
152- const processor = new ( preResolveTypes ? PreResolveTypesProcessor : TypeScriptSelectionSetProcessor ) (
153- processorConfig
154- ) ;
143+ const processor = new PreResolveTypesProcessor ( processorConfig ) ;
155144 this . setSelectionSetHandler (
156145 new SelectionSetToObject (
157146 processor ,
0 commit comments