8000 This provides validation on @oneof input types during validation phase by bbakerman · Pull Request #3577 · graphql-java/graphql-java · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
bbakerman merged 3 commits intomasterfrom
validate-oneof-literals
Jun 2, 2024
Merged

This provides validation on @oneof input types during validation phase#3577
bbakerman merged 3 commits intomasterfrom
validate-oneof-literals

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
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

}

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


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
< 8000 /td> 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!

Co-authored-by: dondonz <13839920+dondonz@users.noreply.github.com>
@bbakerman bbakerman added this pull request to the merge queue Jun 2, 2024
Merged via the queue into master with commit 1ebf1a9 Jun 2, 2024
@jbellenger
Copy link
Contributor

Thanks for doing this!

@dondonz dondonz deleted the validate-oneof-literals branch June 4, 2024 00:16
@dondonz
Copy link
Member
dondonz commented Jun 4, 2024

Thanks for doing this!

Thanks so much for suggesting the improvements!

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.

3 participants

0