From 522076344e79109e89c5c6aed3b3cb0ad6fe3233 Mon Sep 17 00:00:00 2001 From: Casey Foster Date: Mon, 13 Apr 2020 14:45:39 -0500 Subject: [PATCH] Remove isNullable arg, 0.7.3 --- package.json | 2 +- src/execute.js | 11 ++++++++--- src/execute.test.js | 11 +++-------- src/validate-args.js | 8 +++++--- src/validate-query.js | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 648447c..261a729 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pave", "type": "module", - "version": "0.7.2", + "version": "0.7.3", "author": "Casey Foster ", "license": "MIT", "main": "src/index.js", diff --git a/src/execute.js b/src/execute.js index 89d9fbc..2b090a2 100644 --- a/src/execute.js +++ b/src/execute.js @@ -29,8 +29,13 @@ const execute = async ({ let isNullable = true; do { if (isFunction(value)) value = await value(); - else if (type == null) return value == null ? null : value; - else if (!isObject(type)) { + else if (type == null) { + if (value != null) return value; + + if (!isNullable) fail('expectedNonNull'); + + return null; + } else if (!isObject(type)) { if (schema[type]) { obj = null; type = schema[type]; @@ -104,7 +109,7 @@ const execute = async ({ type, value: _args }); - _value = await _value({ args, context, isNullable, obj, query, value }); + _value = await _value({ args, context, obj, query, value }); } if (type.typeArgs) _query._args = type.typeArgs; diff --git a/src/execute.test.js b/src/execute.test.js index 7088e7b..fb6ea74 100644 --- a/src/execute.test.js +++ b/src/execute.test.js @@ -132,12 +132,7 @@ export default async () => { }, NullableString: { name: 'NullableString', - resolve: ({ isNullable, value }) => { - value = value.trim(); - if (!value && isNullable) return null; - - return value; - } + resolve: ({ value }) => value.trim() || null }, Number: { name: 'Number', @@ -163,7 +158,7 @@ export default async () => { }, nullableStringD: { _field: 'nonNullableNullableString', - _args: { string: ' ' } + _args: { string: ' a ' } }, nullableStringE: { _field: 'nullableStringArg', @@ -203,7 +198,7 @@ export default async () => { nullableStringA: 'not null', nullableStringB: null, nullableStringC: 'not null', - nullableStringD: '', + nullableStringD: 'a', nullableStringE: 'not null', nullableStringF: null, selfLink: { diff --git a/src/validate-args.js b/src/validate-args.js index 3b5a0c3..cc8d3fc 100644 --- a/src/validate-args.js +++ b/src/validate-args.js @@ -18,8 +18,11 @@ const _validateArgs = ({ args, context, path = [], schema, type, value }) => { let isNullable = true; do { - if (type == null) return value; - else if (!isObject(type)) { + if (type == null) { + if (value == null && !isNullable) fail('expectedNonNull'); + + return value; + } else if (!isObject(type)) { if (schema[type]) type = schema[type]; else fail('unknownType'); } else if (value === undefined && type.defaultValue !== undefined) { @@ -77,7 +80,6 @@ const _validateArgs = ({ args, context, path = [], schema, type, value }) => { value: args }), context, - isNullable, value }); } diff --git a/src/validate-query.js b/src/validate-query.js index a4b02e1..8edb910 100644 --- a/src/validate-query.js +++ b/src/validate-query.js @@ -77,7 +77,7 @@ const validateQuery = ({ context, path = [], query, schema, type }) => { if (_args !== SKIP_ARGS) { _query._args = validateArgs({ context, - path, + path: path.concat('_args'), schema, type, value: _args