Skip to content
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

This provides validation on @oneof input types during validation phase #3577

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bbakerman
Copy link
Member

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 not f(arg:$variable) which uses the existing code and still is lazy at this stage

re: #3572

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();
Copy link
Member Author

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) {
Copy link
Member Author

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)
Copy link
Member Author

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'"
Copy link
Member Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant