-
Notifications
You must be signed in to change notification settings - Fork 1.1k
This provides validation on @oneof input types during validation phase #3577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Note this is only when the AST literals are present - pure variables are handled later still just like in JS
@@ -95,18 +99,18 @@ public boolean isValidLiteralValue(Value<?> value, GraphQLType type, GraphQLSche | |||
if (type instanceof GraphQLScalarType) { | |||
Optional<GraphQLError> invalid = parseLiteral(value, ((GraphQLScalarType) type).getCoercing(), graphQLContext, locale); | |||
invalid.ifPresent(graphQLError -> handleScalarError(value, (GraphQLScalarType) type, graphQLError)); | |||
return !invalid.isPresent(); | |||
return invalid.isEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yellow squiggly line tweaks
@@ -128,7 +132,7 @@ private Optional<GraphQLError> parseLiteral(Value<?> value, Coercing<?, ?> coerc | |||
} | |||
} | |||
|
|||
boolean isValidLiteralValue(Value<?> value, GraphQLInputObjectType type, GraphQLSchema schema, GraphQLContext graphQLContext, Locale locale) { | |||
boolean isValidLiteralValueForInputObjectType(Value<?> value, GraphQLInputObjectType type, GraphQLSchema schema, GraphQLContext graphQLContext, Locale locale) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed the method to make it clearer on what its doing
@@ -335,6 +335,37 @@ class ArgumentsOfCorrectTypeTest extends Specification { | |||
validationErrors.get(0).message == "Validation error (WrongType@[dog/doesKnowCommand]) : argument 'dogCommand' with value 'EnumValue{name='PRETTY'}' is not a valid 'DogCommand' - Literal value not in allowable values for enum 'DogCommand' - 'EnumValue{name='PRETTY'}'" | |||
} | |||
|
|||
def "invalid @oneOf argument - has more than 1 key - case #why"() { | |||
when: | |||
def validationErrors = validate(query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uses a common specification schema under the covers
then: | ||
validationErrors.size() == 1 | ||
validationErrors.get(0).getValidationErrorType() == ValidationErrorType.WrongType | ||
validationErrors.get(0).message == "Validation error (WrongType@[oneOfField]) : Exactly one key must be specified for argument 'oneOfArg' of @oneOf input type 'oneOfInputType'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan of our validation error messages - and I made them!
One day I wish these where better!
Fixed tests and error messages
Co-authored-by: dondonz <13839920+dondonz@users.noreply.github.com>
Thanks for doing this! |
Thanks so much for suggesting the improvements! |
Note this is only when the AST literals are present - pure variables are handled later still just like in JS
#3572
so
f(arg : { a : "x", b: $y})
will be handled but notf(arg:$variable)
which uses the existing code and still is lazy at this stagere: #3572