Skip to content

Nullable input types not being followed #27

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

Closed
Closed
Show file tree
Hide file tree
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 @@ -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;
Expand All @@ -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;
Expand All @@ -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.
* <p>
*
* <p>
* 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
* <p>
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
}