Skip to content

Commit

Permalink
Remove isNullable arg, 0.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
caseywebdev committed Apr 13, 2020
1 parent f1de517 commit 5220763
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "pave",
"type": "module",
"version": "0.7.2",
"version": "0.7.3",
"author": "Casey Foster <c@sey.me>",
"license": "MIT",
"main": "src/index.js",
Expand Down
11 changes: 8 additions & 3 deletions src/execute.js
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions src/execute.test.js
Expand Up @@ -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',
Expand All @@ -163,7 +158,7 @@ export default async () => {
},
nullableStringD: {
_field: 'nonNullableNullableString',
_args: { string: ' ' }
_args: { string: ' a ' }
},
nullableStringE: {
_field: 'nullableStringArg',
Expand Down Expand Up @@ -203,7 +198,7 @@ export default async () => {
nullableStringA: 'not null',
nullableStringB: null,
nullableStringC: 'not null',
nullableStringD: '',
nullableStringD: 'a',
nullableStringE: 'not null',
nullableStringF: null,
selfLink: {
Expand Down
8 changes: 5 additions & 3 deletions src/validate-args.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -77,7 +80,6 @@ const _validateArgs = ({ args, context, path = [], schema, type, value }) => {
value: args
}),
context,
isNullable,
value
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/validate-query.js
Expand Up @@ -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
Expand Down

0 comments on commit 5220763

Please sign in to comment.