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

make validation errors more configurable #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ protected ErrorClassification buildErrorClassification(String messageTemplate, M
return new ValidationErrorType(fieldOrArgumentPath, directive);
}

/**
* Override this method to build your own error extensions
*
* @param messageTemplate the message template
* @param messageParams the parameters
* @param validationEnvironment the rule environment
*
* @return an Map<String, Object> of extensions
*/
@SuppressWarnings("unused")
protected Map<String, Object> buildErrorExtensions(String messageTemplate, Map<String, Object> messageParams, ValidationEnvironment validationEnvironment) {
return Map.of();
}

/**
* You can override this to provide your own resource bundles for a given locale
*
Expand All @@ -92,11 +106,14 @@ protected ResourceBundle getResourceBundle(Locale locale) {
public GraphQLError interpolate(String messageTemplate, Map<String, Object> messageParams, ValidationEnvironment validationEnvironment) {

ErrorClassification errorClassification = buildErrorClassification(messageTemplate, messageParams, validationEnvironment);
Map<String, Object> errorExtensions = buildErrorExtensions(messageTemplate, messageParams, validationEnvironment);

String message = interpolateMessageImpl(messageTemplate, messageParams, validationEnvironment);

GraphqlErrorBuilder errorBuilder = GraphqlErrorBuilder.newError()
.message(message)
.errorType(errorClassification)
.extensions(errorExtensions)
.path(validationEnvironment.getExecutionPath());
if (validationEnvironment.getLocation() != null) {
errorBuilder.location(validationEnvironment.getLocation());
Expand Down