diff --git a/src/main/java/graphql/validation/interpolation/ResourceBundleMessageInterpolator.java b/src/main/java/graphql/validation/interpolation/ResourceBundleMessageInterpolator.java index f75f41c..daaa0f6 100644 --- a/src/main/java/graphql/validation/interpolation/ResourceBundleMessageInterpolator.java +++ b/src/main/java/graphql/validation/interpolation/ResourceBundleMessageInterpolator.java @@ -7,7 +7,6 @@ import graphql.schema.GraphQLDirective; import graphql.validation.el.StandardELVariables; import graphql.validation.rules.ValidationEnvironment; -import javax.validation.Path; import org.hibernate.validator.internal.engine.MessageInterpolatorContext; import org.hibernate.validator.internal.metadata.core.ConstraintHelper; import org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl; @@ -18,6 +17,7 @@ import org.hibernate.validator.spi.resourceloading.ResourceBundleLocator; import javax.validation.Constraint; +import javax.validation.Path; import javax.validation.Payload; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -40,7 +40,7 @@ * This message interpolator will try to convert message templates into I18N messages and then run message property replacement * and expression interpolation. *
- * + *
* By default this looks for a resource bundle file called "ValidationMessages.properties" on the class path but you can can * override {@link #getResourceBundle(java.util.Locale)} to provide your own resource bundle *
@@ -65,7 +65,6 @@ public class ResourceBundleMessageInterpolator implements MessageInterpolator { * @param messageTemplate the message template * @param messageParams the parameters * @param validationEnvironment the rule environment - * * @return an ErrorClassification */ @SuppressWarnings("unused") @@ -79,7 +78,6 @@ protected ErrorClassification buildErrorClassification(String messageTemplate, M * You can override this to provide your own resource bundles for a given locale * * @param locale the locale in question - * * @return a resource bundle OR null if you don't have one */ @SuppressWarnings("unused") @@ -201,5 +199,12 @@ public Object toSpecification(GraphQLError error) { } return map; } + + @Override + public String toString() { + String path = fieldOrArgumentPath.toString(); + String directive = this.directive != null ? " @" + this.directive.getName() : ""; + return "ExtendedValidationError: '" + path + "'" + directive; + } } } diff --git a/src/test/groovy/graphql/validation/rules/ValidationRulesTest.groovy b/src/test/groovy/graphql/validation/rules/ValidationRulesTest.groovy index 16ec98f..75fe24d 100644 --- a/src/test/groovy/graphql/validation/rules/ValidationRulesTest.groovy +++ b/src/test/groovy/graphql/validation/rules/ValidationRulesTest.groovy @@ -3,9 +3,11 @@ package graphql.validation.rules import graphql.GraphQL import graphql.execution.DataFetcherResult import graphql.schema.DataFetcher +import graphql.schema.DataFetchingEnvironment import graphql.schema.idl.RuntimeWiring import graphql.validation.TestUtil import graphql.validation.constraints.DirectiveConstraints +import graphql.validation.schemawiring.ValidationSchemaWiring import spock.lang.Specification import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring @@ -78,4 +80,58 @@ class ValidationRulesTest extends Specification { er.errors[2].message == "/cars/filter/model size must be between 0 and 10" er.errors[2].path == ["cars"] } + + def "issue 17 - type references handled"() { + + def directiveRules = DirectiveConstraints.newDirectiveConstraints().build() + + def sdl = ''' + + ''' + directiveRules.directivesSDL + ''' + + input NameRequest { + # The title associated to the name + title: String @Size(min : 1, max : 1) + # The given name + givenName: String! @Size(min : 1, max : 1) + # Middle Name + middleName: String + # Last Name + surName: String! + } + + type Query { + request( nameRequest : NameRequest!) : String + } + ''' + + ValidationRules validationRules = ValidationRules.newValidationRules() + .onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL).build() + def validationWiring = new ValidationSchemaWiring(validationRules) + + DataFetcher df = { DataFetchingEnvironment env -> + return "OK" + } + + def runtime = RuntimeWiring.newRuntimeWiring() + .type(newTypeWiring("Query").dataFetcher("request", df)) + .directiveWiring(validationWiring) + .build() + def graphQLSchema = TestUtil.schema(sdl, runtime) + def graphQL = GraphQL.newGraphQL(graphQLSchema).build() + + when: + + def er = graphQL.execute(''' + { + request (nameRequest : { title : "Mr BAD", givenName : "BADLEY" , surName : "FAKER"}) + } + ''') + then: + er != null + er.errors.size() != 0 + + er.errors[0].getMessage() == "/request/nameRequest/givenName size must be between 1 and 1" + er.errors[1].getMessage() == "/request/nameRequest/title size must be between 1 and 1" + } }