11import assert from 'assert' ;
22import JSON5 from 'json5' ;
3- import { remove } from 'lodash' ;
3+ import { castArray , remove , trim } from 'lodash' ;
44import {
55 ClassDeclarationStructure ,
66 CommentStatement ,
@@ -99,16 +99,27 @@ export function modelOutputType(outputType: OutputType, args: EventArguments) {
9999 fileType = 'output' ;
100100 outputTypeName = getOutputTypeName ( outputTypeName ) ;
101101 }
102- const customType = config . types [ outputTypeName ] ;
102+ const customType = config . types [ outputTypeName ] ; // todo: remove
103103 const modelField = modelFields . get ( model . name ) ?. get ( field . name ) ;
104104 const settings = fieldSettings . get ( model . name ) ?. get ( field . name ) ;
105+ const fieldType = settings ?. getFieldType ( ) ;
106+ const propertySettings = settings ?. getPropertyType ( ) ;
107+
108+ const propertyType = castArray (
109+ propertySettings ?. name ||
110+ customType ?. fieldType ?. split ( '|' ) . map ( trim ) ||
111+ getPropertyType ( {
112+ location,
113+ type : outputTypeName ,
114+ } ) ,
115+ ) ;
116+
117+ // For model we keep only one type
118+ propertyType . splice ( 1 , propertyType . length ) ;
105119
106- const propertyType = customType ?. fieldType
107- ? [ customType . fieldType ]
108- : getPropertyType ( {
109- location,
110- type : outputTypeName ,
111- } ) ;
120+ if ( field . isNullable && ! isList && [ 'enumTypes' , 'scalar' ] . includes ( location ) ) {
121+ propertyType . push ( 'null' ) ;
122+ }
112123
113124 // For model we keep only one type
114125 propertyType . splice ( 1 , propertyType . length ) ;
@@ -118,7 +129,6 @@ export function modelOutputType(outputType: OutputType, args: EventArguments) {
118129 }
119130
120131 let graphqlType : string ;
121- const fieldType = settings ?. getFieldType ( ) ;
122132
123133 if ( fieldType ) {
124134 graphqlType = fieldType . name ;
@@ -164,6 +174,10 @@ export function modelOutputType(outputType: OutputType, args: EventArguments) {
164174
165175 classStructure . properties ?. push ( property ) ;
166176
177+ if ( propertySettings ) {
178+ importDeclarations . create ( { ...propertySettings } ) ;
179+ }
180+
167181 // Create import for typescript field/property type
168182 if ( customType && customType . fieldType && customType . fieldModule ) {
169183 importDeclarations . add ( customType . fieldType , customType . fieldModule ) ;
@@ -190,7 +204,7 @@ export function modelOutputType(outputType: OutputType, args: EventArguments) {
190204 } ) ;
191205
192206 for ( const options of settings || [ ] ) {
193- if ( ! options . output || options . isFieldType ) {
207+ if ( ! options . output || options . kind !== 'Decorator' ) {
194208 continue ;
195209 }
196210 property . decorators ?. push ( {
0 commit comments