( schema: TypeNode, defaultValue?: any, allowNull?: boolean, )
| 23 | type TypeNode = any; |
| 24 | |
| 25 | const unwrapSchema = ( |
| 26 | schema: TypeNode, |
| 27 | defaultValue?: any, |
| 28 | allowNull?: boolean, |
| 29 | ): [any, any, boolean] => { |
| 30 | const ast = schema.ast || schema; |
| 31 | const type = ast._tag; |
| 32 | if (type === UNION) { |
| 33 | const types = ast.types; |
| 34 | const nonNullType = arrayFind( |
| 35 | types, |
| 36 | (t: TypeNode) => !(t._tag === LITERAL && isNull(t.literal)), |
| 37 | ); |
| 38 | return [ |
| 39 | {[TYPE]: getSimpleType(nonNullType)}, |
| 40 | defaultValue, |
| 41 | allowNull || |
| 42 | !!arrayFind( |
| 43 | types, |
| 44 | (t: TypeNode) => t._tag === LITERAL && isNull(t.literal), |
| 45 | ), |
| 46 | ]; |
| 47 | } |
| 48 | |
| 49 | return [{[TYPE]: getSimpleType(ast)}, defaultValue, allowNull || false]; |
| 50 | }; |
| 51 | |
| 52 | const getSimpleType = (ast: TypeNode): string => { |
| 53 | const tag = ast?._tag; |
nothing calls this directly
no test coverage detected
searching dependent graphs…