From 0744a4fa67de84d3dcf2918c0cffa0851aafc460 Mon Sep 17 00:00:00 2001 From: Quentin AUBERT Date: Thu, 11 Jul 2024 11:00:55 +0200 Subject: [PATCH] FIX input as object can be nullable --- src/resolvers/utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/resolvers/utils.ts b/src/resolvers/utils.ts index 4b672c2..1bcc167 100644 --- a/src/resolvers/utils.ts +++ b/src/resolvers/utils.ts @@ -21,7 +21,7 @@ export const buildSubResolver = (props: SchemaEntry, key: string, dependencies: const { constraints = [] } = props; if (props.array || props.isMulti) { let subResolver; - let arrayResolver = yup.array() + let arrayResolver = yup.array().nullable().optional() if (props.schema) { const deps: Array<[string, string]> = []; @@ -44,12 +44,12 @@ export const buildSubResolver = (props: SchemaEntry, key: string, dependencies: return arrayResolver } else if (props.type === type.object && props.schema) { if (!Object.keys(props.schema).length) { - return yup.object() + return yup.object().nullable().optional() } const subResolver = getShapeAndDependencies(props.flow || Object.keys(props.schema), props.schema, dependencies, rawValues); return constraints.reduce((resolver, constraint) => { return jsonOrFunctionConstraint(constraint, resolver, key, dependencies) - }, yup.object().shape(subResolver.shape, dependencies)) + }, yup.object().nullable().optional().shape(subResolver.shape, dependencies)) } else if (props.type === type.object && props.conditionalSchema) { const { schema, flow } = option(props.conditionalSchema) .map(condiSchema => { @@ -74,7 +74,7 @@ export const buildSubResolver = (props: SchemaEntry, key: string, dependencies: const subResolver = getShapeAndDependencies(flow || Object.keys(schema), schema, dependencies, rawValues); return constraints.reduce((resolver, constraint) => { return jsonOrFunctionConstraint(constraint, resolver, key, dependencies) - }, yup.object().shape(subResolver.shape, dependencies)) + }, yup.object().nullable().optional().shape(subResolver.shape, dependencies)) } else { return constraints.reduce((resolver, constraint) => { return jsonOrFunctionConstraint(constraint, resolver, key, dependencies)