File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ import {
55 TypeNode ,
66} from "graphql" ;
77
8- export const isListType = ( typ : TypeNode ) : typ is ListTypeNode =>
9- typ . kind === "ListType" ;
10- export const isNonNullType = ( typ : TypeNode ) : typ is NonNullTypeNode =>
11- typ . kind === "NonNullType" ;
12- export const isNamedType = ( typ : TypeNode ) : typ is NamedTypeNode =>
13- typ . kind === "NamedType" ;
8+ export const isListType = ( typ ? : TypeNode ) : typ is ListTypeNode =>
9+ typ ? .kind === "ListType" ;
10+ export const isNonNullType = ( typ ? : TypeNode ) : typ is NonNullTypeNode =>
11+ typ ? .kind === "NonNullType" ;
12+ export const isNamedType = ( typ ? : TypeNode ) : typ is NamedTypeNode =>
13+ typ ? .kind === "NamedType" ;
1414
1515export const isInput = ( kind : string ) => kind . includes ( "Input" ) ;
Original file line number Diff line number Diff line change @@ -128,21 +128,27 @@ const generateInputObjectFieldYupSchema = (
128128const generateInputObjectFieldTypeYupSchema = (
129129 tsVisitor : TsVisitor ,
130130 schema : GraphQLSchema ,
131- type : TypeNode
131+ type : TypeNode ,
132+ parentType ?: TypeNode
132133) : string => {
133134 if ( isListType ( type ) ) {
134135 const gen = generateInputObjectFieldTypeYupSchema (
135136 tsVisitor ,
136137 schema ,
137- type . type
138+ type . type ,
139+ type ,
138140 ) ;
141+ if ( ! isNonNullType ( parentType ) ) {
142+ return `yup.array().of(${ maybeLazy ( type . type , gen ) } ).optional()` ;
143+ }
139144 return `yup.array().of(${ maybeLazy ( type . type , gen ) } )` ;
140145 }
141146 if ( isNonNullType ( type ) ) {
142147 const gen = generateInputObjectFieldTypeYupSchema (
143148 tsVisitor ,
144149 schema ,
145- type . type
150+ type . type ,
151+ type ,
146152 ) ;
147153 return maybeLazy ( type . type , `${ gen } .required()` ) ;
148154 }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ input PageInput {
1616 attributes : [AttributeInput ! ]
1717 pageType : PageType !
1818 date : Date
19+ postIDs : [ID ! ]
1920}
2021
2122input AttributeInput {
You can’t perform that action at this time.
0 commit comments