From f762cfc577f69ed9ebc86c93b3a842b717b1506c Mon Sep 17 00:00:00 2001 From: mr-c Date: Mon, 16 Oct 2023 15:29:16 -0700 Subject: [PATCH 1/5] adding support for the id scalar constrained as a string --- lib/type-utils.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/type-utils.js b/lib/type-utils.js index 651c639..5addaa7 100644 --- a/lib/type-utils.js +++ b/lib/type-utils.js @@ -4,13 +4,14 @@ const { GraphQLString, isNonNullType, isScalarType, - isListType + isListType, + GraphQLID } = require('graphql') const { ConstraintStringType, validate: validateStringFn } = require('../scalars/string') const { ConstraintNumberType, validate: validateNumberFn } = require('../scalars/number') function getConstraintTypeObject (fieldName, type, uniqueTypeName, directiveArgumentMap) { - if (type === GraphQLString) { + if (type === GraphQLString || type === GraphQLID) { return new ConstraintStringType( fieldName, uniqueTypeName, From bedb9401dc9c55d2e4cb426a8b597d07e18f68e2 Mon Sep 17 00:00:00 2001 From: mr-c Date: Mon, 16 Oct 2023 16:15:41 -0700 Subject: [PATCH 2/5] updating the validatefn as well --- lib/type-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/type-utils.js b/lib/type-utils.js index 5addaa7..f1053b8 100644 --- a/lib/type-utils.js +++ b/lib/type-utils.js @@ -31,7 +31,7 @@ function getConstraintTypeObject (fieldName, type, uniqueTypeName, directiveArgu } function getConstraintValidateFn (type) { - if (type === GraphQLString) { + if (type === GraphQLString || type === GraphQLID) { return validateStringFn } else if (type === GraphQLFloat || type === GraphQLInt) { return validateNumberFn From cc0e2e8afc5c6e36a8bbed6bf649d19596165b66 Mon Sep 17 00:00:00 2001 From: mr-c Date: Mon, 16 Oct 2023 17:29:12 -0700 Subject: [PATCH 3/5] passing options for typed array --- lib/query-validation-visitor.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/query-validation-visitor.js b/lib/query-validation-visitor.js index dbbc190..0ee377b 100644 --- a/lib/query-validation-visitor.js +++ b/lib/query-validation-visitor.js @@ -137,7 +137,7 @@ module.exports = class QueryValidationVisitor { validateInputTypeValue(this.context, inputObjectTypeDef, argName, variableName, value, this.currentField, variableName, this.options) } else if (isListType(valueTypeDef)) { - validateArrayTypeValue(this.context, valueTypeDef, argTypeDef, value, this.currentField, argName, variableName, variableName) + validateArrayTypeValue(this.context, valueTypeDef, argTypeDef, value, this.currentField, argName, variableName, variableName, this.options) } else { // nothing to validate if (!value && value !== '' && value !== 0) return @@ -184,7 +184,7 @@ function validateInputTypeValue (context, inputObjectTypeDef, argName, variableN visit(inputObjectTypeDef.astNode, visitor) } -function validateArrayTypeValue (context, valueTypeDef, typeDefWithDirective, value, currentField, argName, variableName, iFieldNameFull) { +function validateArrayTypeValue (context, valueTypeDef, typeDefWithDirective, value, currentField, argName, variableName, iFieldNameFull, options) { if (!typeDefWithDirective.astNode) { return } let valueTypeDefArray = valueTypeDef.ofType @@ -228,9 +228,8 @@ function validateArrayTypeValue (context, valueTypeDef, typeDefWithDirective, va if (value) { value.forEach((element, index) => { const iFieldNameFullIndexed = iFieldNameFull ? `${iFieldNameFull}[${index++}]` : `[${index++}]` - if (isInputObjectType(valueTypeDefArray)) { - validateInputTypeValue(context, valueTypeDefArray, argName, variableName, element, currentField, iFieldNameFullIndexed, this.options) + validateInputTypeValue(context, valueTypeDefArray, argName, variableName, element, currentField, iFieldNameFullIndexed, options ?? this.options) } else if (hasNonListValidation) { const atMessage = ` at "${iFieldNameFullIndexed}"` @@ -276,7 +275,7 @@ class InputObjectValidationVisitor { validateInputTypeValue(this.context, valueTypeDef, this.argName, this.variableName, value, this.currentField, iFieldNameFull, this.options) } else if (isListType(valueTypeDef)) { - validateArrayTypeValue(this.context, valueTypeDef, iFieldTypeDef, value, this.currentField, this.argName, this.variableName, iFieldNameFull) + validateArrayTypeValue(this.context, valueTypeDef, iFieldTypeDef, value, this.currentField, this.argName, this.variableName, iFieldNameFull, this.options) } else { // nothing to validate if (!value && value !== '' && value !== 0) return From 06cf1b81c019f87e7377ec570886df681a2b01a3 Mon Sep 17 00:00:00 2001 From: mr-c Date: Mon, 16 Oct 2023 17:29:47 -0700 Subject: [PATCH 4/5] passing options for typed array --- lib/query-validation-visitor.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/query-validation-visitor.js b/lib/query-validation-visitor.js index 0ee377b..e0d3806 100644 --- a/lib/query-validation-visitor.js +++ b/lib/query-validation-visitor.js @@ -232,8 +232,7 @@ function validateArrayTypeValue (context, valueTypeDef, typeDefWithDirective, va validateInputTypeValue(context, valueTypeDefArray, argName, variableName, element, currentField, iFieldNameFullIndexed, options ?? this.options) } else if (hasNonListValidation) { const atMessage = ` at "${iFieldNameFullIndexed}"` - - validateScalarTypeValue(context, currentField, typeDefWithDirective, valueTypeDef, element, variableName, argName, iFieldNameFullIndexed, atMessage, this.options) + validateScalarTypeValue(context, currentField, typeDefWithDirective, valueTypeDef, element, variableName, argName, iFieldNameFullIndexed, atMessage, options ?? this.options) } }) } From ff5d4247108a8dcf18d958dd0505594f74f2a408 Mon Sep 17 00:00:00 2001 From: mr-c Date: Mon, 16 Oct 2023 17:37:57 -0700 Subject: [PATCH 5/5] reverting this for this branch --- lib/type-utils.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/type-utils.js b/lib/type-utils.js index f1053b8..651c639 100644 --- a/lib/type-utils.js +++ b/lib/type-utils.js @@ -4,14 +4,13 @@ const { GraphQLString, isNonNullType, isScalarType, - isListType, - GraphQLID + isListType } = require('graphql') const { ConstraintStringType, validate: validateStringFn } = require('../scalars/string') const { ConstraintNumberType, validate: validateNumberFn } = require('../scalars/number') function getConstraintTypeObject (fieldName, type, uniqueTypeName, directiveArgumentMap) { - if (type === GraphQLString || type === GraphQLID) { + if (type === GraphQLString) { return new ConstraintStringType( fieldName, uniqueTypeName, @@ -31,7 +30,7 @@ function getConstraintTypeObject (fieldName, type, uniqueTypeName, directiveArgu } function getConstraintValidateFn (type) { - if (type === GraphQLString || type === GraphQLID) { + if (type === GraphQLString) { return validateStringFn } else if (type === GraphQLFloat || type === GraphQLInt) { return validateNumberFn