Skip to content

Conversation

@dondonz
Copy link
Member

@dondonz dondonz commented Jul 4, 2022

Adding i18n messages for validation errors. We are starting with validation errors, as they occur most frequently.

This PR follows on from @bbakerman's i18n PR #1473, I have copied the core i18n ideas into this PR, brought it up to date and expanded tests.

Coming up in the next PR - German and Portuguese translations

id
}
}
"""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the Lone Anonymous test file - it's hard to find tests via spec number

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the naming. It should always be a descriptive name.

@@ -1,133 +0,0 @@
package graphql.validation
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into rule test, it's hard to find tests via spec number

@@ -1,26 +0,0 @@
package graphql.validation
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into rule test, it's hard to find tests via spec number

validationErrors.size() == 1
validationErrors.get(0).getValidationErrorType() == ValidationErrorType.VariableTypeMismatch
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into rule test, it's hard to find tests via spec number

@@ -1,47 +0,0 @@
package graphql.validation.rules
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 to ScalarLeavesTest, diff makes it look like a deletion

def er = customScalarSchema.execute(ei)
then:
er.errors.size() == 1
er.errors[0].message.contains("parseLiteral message")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coercing error messages remain the same as before, not i18n-ised.

@dondonz dondonz changed the title I18n for validation error messages (WIP) I18n for validation error messages Jul 12, 2022
@dondonz dondonz requested a review from bbakerman July 13, 2022 03:57
Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great - it was less invasive than I thought - albeit still wide reaching

*
* @return a result object that indicates how this operation went
*/
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. Leave the old and use Locale.getDefault() in it and delegate to the old method

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, I'll change this

* @return a result object that indicates how this operation went
*/
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Predicate<Class<?>> rulePredicate) {
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Predicate<Class<?>> rulePredicate, Locale locale) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same breaking change- leave the old, use Locale.getDefault() and win

return msgArguments.toArray();
}

public I18nMsg argumentAt(int index, Object argument) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably named this method but on reflectionaddArgumentAt is a better name

executionInput.locale == Locale.ENGLISH
executionInput.dataLoaderRegistry != null
executionInput.variables == [:]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test to show it now defaults when build but not set

Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@bbakerman bbakerman added this to the 19.0 milestone Jul 22, 2022
@dondonz dondonz merged commit 532d6bb into master Jul 22, 2022
@dondonz dondonz deleted the validation-error-refactor branch July 22, 2022 07:08
@yeikel
Copy link
Contributor

yeikel commented Jul 28, 2022

Defaulting the locale is a small regression for anyone that did not assume this behavior. Maybe this should be noted in the release notes? See https://github.com/vert-x3/vertx-web/pull/2244/files#r931731703

@dondonz
Copy link
Member Author

dondonz commented Jul 28, 2022

Hi @yeikel thanks for letting me know. I'll amend the release notes

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.

5 participants