Skip to content

Commit 8bab116

Browse files
authored
Graphql java 14 stable (#23)
* Revert "refactor(*): Upgrade to GraphQL Java 15.0 (#16)" This reverts commit 4c08118 * Updating to latest hibernate-validation dependency to match what is defaulted in spring-boot-starter-parent 2.3.0.RELEASE and above * Updating to latest graphql-java:14.1, slf4j:1.7.30
1 parent 4c08118 commit 8bab116

File tree

7 files changed

+25
-26
lines changed

7 files changed

+25
-26
lines changed

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,15 @@ But the project welcomes all feedback and input on code design and validation re
2121
<dependency>
2222
<groupId>com.graphql-java</groupId>
2323
<artifactId>graphql-java-extended-validation</artifactId>
24-
<version>0.0.5</version>
24+
<version>0.0.3</version>
2525
<type>pom</type>
2626
</dependency>
2727
```
2828

2929
```groovy
30-
compile 'com.graphql-java:graphql-java-extended-validation:0.0.5'
30+
compile 'com.graphql-java:graphql-java-extended-validation:0.0.3'
3131
```
3232

33-
> Note:
34-
>
35-
> use 0.0.3 or below for graphql-java 13.x and below
36-
>
37-
> use 0.0.4 or above for graphql-java 14.x and above
38-
3933
Its currently available from JCenter repo and Maven central is pending.
4034

4135

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ repositories {
3939

4040

4141
dependencies {
42-
compile "com.graphql-java:graphql-java:15.0"
42+
compile "com.graphql-java:graphql-java:14.1"
4343
compile 'org.slf4j:slf4j-api:1.7.30'
4444
compile "jakarta.validation:jakarta.validation-api:2.0.2"
45-
compile "org.hibernate.validator:hibernate-validator:6.0.19.Final"
45+
compile "org.hibernate.validator:hibernate-validator:6.1.5.Final"
4646
compile "jakarta.el:jakarta.el-api:3.0.3"
4747
compile "org.glassfish:jakarta.el:3.0.3"
4848

src/main/java/graphql/validation/constraints/AbstractDirectiveConstraint.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static graphql.schema.GraphQLTypeUtil.isList;
2929
import static graphql.validation.rules.ValidationEnvironment.ValidatedElement.FIELD;
3030
import static graphql.validation.util.Util.mkMap;
31-
import static java.lang.String.format;
3231
import static java.util.Collections.singletonList;
3332

3433
@SuppressWarnings("UnnecessaryLocalVariable")
@@ -73,10 +72,10 @@ public boolean appliesTo(GraphQLArgument argument, GraphQLFieldDefinition fieldD
7372
if (appliesToType) {
7473
return true;
7574
}
76-
// if they have a @Directive on there BUT it can't handle that type
75+
// if they have a @Directive on there BUT it cant handle that type
7776
// then is a really bad situation
7877
String argType = GraphQLTypeUtil.simplePrint(inputType);
79-
Assert.assertTrue(false, () -> format("The directive rule '%s' cannot be placed on elements of type '%s'", "@" + this.getName(), argType));
78+
Assert.assertTrue(false, "The directive rule '%s' cannot be placed on elements of type '%s'", "@" + this.getName(), argType);
8079
}
8180
return false;
8281
});
@@ -326,7 +325,7 @@ protected boolean isStringOrListOrMap(GraphQLInputType inputType) {
326325
*/
327326
@SuppressWarnings("ConstantConditions")
328327
protected Map asMap(Object value) {
329-
Assert.assertTrue(value instanceof Map, () -> "The argument value MUST be a Map value");
328+
Assert.assertTrue(value instanceof Map, "The argument value MUST be a Map value");
330329
return (Map) value;
331330
}
332331

src/main/java/graphql/validation/interpolation/ResourceBundleMessageInterpolator.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
import graphql.schema.GraphQLDirective;
88
import graphql.validation.el.StandardELVariables;
99
import graphql.validation.rules.ValidationEnvironment;
10+
import javax.validation.Path;
1011
import org.hibernate.validator.internal.engine.MessageInterpolatorContext;
1112
import org.hibernate.validator.internal.metadata.core.ConstraintHelper;
1213
import org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl;
14+
import org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl.ConstraintType;
15+
import org.hibernate.validator.internal.metadata.location.ConstraintLocation.ConstraintLocationKind;
1316
import org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor;
1417
import org.hibernate.validator.resourceloading.PlatformResourceBundleLocator;
1518
import org.hibernate.validator.spi.resourceloading.ResourceBundleLocator;
1619

1720
import javax.validation.Constraint;
1821
import javax.validation.Payload;
19-
import java.lang.annotation.ElementType;
2022
import java.lang.annotation.Retention;
2123
import java.lang.annotation.Target;
2224
import java.util.LinkedHashMap;
@@ -148,16 +150,18 @@ private MessageInterpolatorContext buildHibernateContext(Map<String, Object> mes
148150

149151
ConstraintDescriptorImpl<BridgeAnnotation> constraintDescriptor
150152
= new ConstraintDescriptorImpl<>(
151-
new ConstraintHelper(), null,
152-
annotationDescriptor, ElementType.FIELD
153+
ConstraintHelper.forAllBuiltinConstraints(), null,
154+
annotationDescriptor, ConstraintLocationKind.FIELD, ConstraintType.GENERIC
153155
);
154156

155157
Map<String, Object> expressionVariables = StandardELVariables.standardELVars(validationEnvironment);
156158

157159
Class<?> rootBeanType = null;
160+
Path propertyPath = null;
161+
158162
return new MessageInterpolatorContext(
159163
constraintDescriptor, validatedValue, rootBeanType,
160-
messageParams, expressionVariables);
164+
propertyPath, messageParams, expressionVariables);
161165
}
162166

163167
private org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator hibernateInterpolator() {

src/main/java/graphql/validation/util/Util.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ public static ExecutionPath concatPaths(ExecutionPath parent, ExecutionPath chil
104104
*/
105105
public static Map<String, Object> mkMap(Object... args) {
106106
Map<String, Object> params = new LinkedHashMap<>();
107-
Assert.assertTrue(args.length % 2 == 0, () -> "You MUST pass in an even number of arguments");
107+
Assert.assertTrue(args.length % 2 == 0, "You MUST pass in an even number of arguments");
108108
for (int ix = 0; ix < args.length; ix = ix + 2) {
109109
Object key = args[ix];
110-
Assert.assertTrue(key instanceof String, () -> "You MUST pass in a message param string key");
110+
Assert.assertTrue(key instanceof String, "You MUST pass in a message param string key");
111111
Object val = args[ix + 1];
112112
params.put(String.valueOf(key), val);
113113
}

src/test/groovy/ELDiscover.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.hibernate.validator.internal.engine.path.PathImpl;
44
import org.hibernate.validator.internal.metadata.core.ConstraintHelper;
55
import org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl;
6+
import org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl.ConstraintType;
7+
import org.hibernate.validator.internal.metadata.location.ConstraintLocation.ConstraintLocationKind;
68
import org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor;
79
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
810

@@ -14,7 +16,6 @@
1416
import javax.validation.MessageInterpolator;
1517
import javax.validation.constraints.Email;
1618
import javax.validation.constraints.NotNull;
17-
import java.lang.annotation.ElementType;
1819
import java.lang.reflect.Method;
1920
import java.util.Collections;
2021
import java.util.HashMap;
@@ -88,10 +89,11 @@ public static void main(String[] args) throws Exception {
8889
= new ConstraintAnnotationDescriptor.Builder<>(NotNull.class, attributes);
8990

9091
ConstraintDescriptorImpl<NotNull> constraintDescriptor = new ConstraintDescriptorImpl<>(
91-
new ConstraintHelper(),
92+
ConstraintHelper.forAllBuiltinConstraints(),
9293
null,
9394
constraintBuilder.build(),
94-
ElementType.FIELD
95+
ConstraintLocationKind.FIELD,
96+
ConstraintType.GENERIC
9597
);
9698

9799

@@ -103,7 +105,7 @@ public static void main(String[] args) throws Exception {
103105
PathImpl rootPath = PathImpl.createRootPath();
104106

105107
MessageInterpolator.Context context = new MessageInterpolatorContext(
106-
constraintDescriptor, user, null, Collections.emptyMap(), Collections.emptyMap());
108+
constraintDescriptor, user, null, rootPath, Collections.emptyMap(), Collections.emptyMap());
107109

108110
print("${validatedValue.age}", messageInterpolator, context);
109111
print("${validatedValue}", messageInterpolator, context);

src/test/groovy/graphql/validation/TestUtil.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class TestUtil {
6666
def stream = TestUtil.class.getClassLoader().getResourceAsStream(fileName)
6767

6868
def typeRegistry = new SchemaParser().parse(new InputStreamReader(stream))
69-
def options = SchemaGenerator.Options.defaultOptions()
69+
def options = SchemaGenerator.Options.defaultOptions().enforceSchemaDirectives(false)
7070
def schema = new SchemaGenerator().makeExecutableSchema(options, typeRegistry, wiring)
7171
schema
7272
}
@@ -103,7 +103,7 @@ class TestUtil {
103103
static GraphQLSchema schema(Reader specReader, RuntimeWiring runtimeWiring) {
104104
try {
105105
def registry = new SchemaParser().parse(specReader)
106-
def options = SchemaGenerator.Options.defaultOptions()
106+
def options = SchemaGenerator.Options.defaultOptions().enforceSchemaDirectives(false)
107107
return new SchemaGenerator().makeExecutableSchema(options, registry, runtimeWiring)
108108
} catch (SchemaProblem e) {
109109
assert false: "The schema could not be compiled : ${e}"

0 commit comments

Comments
 (0)