Skip to content

Commit 72c4a1d

Browse files
Merge pull request #116 from phocassoftware/RBT-928-pass-through-jakarta-annotations-try-2
RBT-928 pass through jakarta annotations
2 parents b529abe + 50e0b05 commit 72c4a1d

File tree

11 files changed

+449
-223
lines changed

11 files changed

+449
-223
lines changed

graphql-builder/pom.xml

Lines changed: 98 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,99 +11,108 @@
1111
the License.
1212
1313
-->
14-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
15-
<modelVersion>4.0.0</modelVersion>
16-
<name>graphql-builder</name>
17-
<description>Builds a graphql schema from a model using reflection</description>
14+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
<name>graphql-builder</name>
18+
<description>Builds a graphql schema from a model using reflection</description>
1819

19-
<parent>
20-
<groupId>com.phocassoftware</groupId>
21-
<artifactId>graphql-builder-parent</artifactId>
22-
<version>1.1.0-SNAPSHOT</version>
23-
</parent>
20+
<parent>
21+
<groupId>com.phocassoftware</groupId>
22+
<artifactId>graphql-builder-parent</artifactId>
23+
<version>1.1.0-SNAPSHOT</version>
24+
</parent>
2425

25-
<artifactId>graphql-builder</artifactId>
26+
<artifactId>graphql-builder</artifactId>
2627

27-
<properties>
28-
<junit.jupiter.version>5.13.0</junit.jupiter.version>
29-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30-
<jackson.version>2.19.0</jackson.version>
31-
<graphql.version>24.1</graphql.version>
32-
</properties>
28+
<properties>
29+
<junit.jupiter.version>5.13.0</junit.jupiter.version>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<jackson.version>2.19.0</jackson.version>
32+
<graphql.version>24.1</graphql.version>
33+
</properties>
3334

34-
<licenses>
35-
<license>
36-
<name>Apache License, Version 2.0</name>
37-
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
38-
<distribution>repo</distribution>
39-
</license>
40-
</licenses>
35+
<licenses>
36+
<license>
37+
<name>Apache License, Version 2.0</name>
38+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
39+
<distribution>repo</distribution>
40+
</license>
41+
</licenses>
4142

42-
<dependencies>
43-
<dependency>
44-
<groupId>com.graphql-java</groupId>
45-
<artifactId>graphql-java</artifactId>
46-
<version>${graphql.version}</version>
47-
</dependency>
48-
<dependency>
49-
<groupId>com.graphql-java</groupId>
50-
<artifactId>graphql-java-extended-scalars</artifactId>
51-
<version>21.0</version>
52-
<scope>test</scope>
53-
</dependency>
54-
<dependency>
55-
<groupId>org.reflections</groupId>
56-
<artifactId>reflections</artifactId>
57-
<version>0.10.2</version>
58-
</dependency>
59-
<dependency>
60-
<groupId>jakarta.annotation</groupId>
61-
<artifactId>jakarta.annotation-api</artifactId>
62-
<version>3.0.0</version>
63-
</dependency>
64-
<dependency>
65-
<groupId>com.fasterxml.jackson.core</groupId>
66-
<artifactId>jackson-databind</artifactId>
67-
<version>${jackson.version}</version>
68-
<scope>test</scope>
69-
</dependency>
70-
<dependency>
71-
<groupId>com.fasterxml.jackson.module</groupId>
72-
<artifactId>jackson-module-parameter-names</artifactId>
73-
<version>${jackson.version}</version>
74-
<scope>test</scope>
75-
</dependency>
76-
<dependency>
77-
<groupId>com.fasterxml.jackson.datatype</groupId>
78-
<artifactId>jackson-datatype-jdk8</artifactId>
79-
<version>${jackson.version}</version>
80-
<scope>test</scope>
81-
</dependency>
82-
<dependency>
83-
<groupId>com.fasterxml.jackson.datatype</groupId>
84-
<artifactId>jackson-datatype-jsr310</artifactId>
85-
<version>${jackson.version}</version>
86-
<scope>test</scope>
87-
</dependency>
88-
<dependency>
89-
<groupId>io.reactivex.rxjava3</groupId>
90-
<artifactId>rxjava</artifactId>
91-
<version>3.1.10</version>
92-
<scope>test</scope>
93-
</dependency>
43+
<dependencies>
44+
<dependency>
45+
<groupId>com.graphql-java</groupId>
46+
<artifactId>graphql-java</artifactId>
47+
<version>${graphql.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.graphql-java</groupId>
51+
<artifactId>graphql-java-extended-scalars</artifactId>
52+
<version>24.0</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.graphql-java</groupId>
56+
<artifactId>graphql-java-extended-validation</artifactId>
57+
<version>24.0</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.reflections</groupId>
61+
<artifactId>reflections</artifactId>
62+
<version>0.10.2</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>jakarta.annotation</groupId>
66+
<artifactId>jakarta.annotation-api</artifactId>
67+
<version>3.0.0</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>jakarta.validation</groupId>
71+
<artifactId>jakarta.validation-api</artifactId>
72+
<version>3.1.0</version>
73+
</dependency>
9474

95-
<dependency>
96-
<groupId>org.junit.jupiter</groupId>
97-
<artifactId>junit-jupiter</artifactId>
98-
<version>${junit.jupiter.version}</version>
99-
<scope>test</scope>
100-
</dependency>
101-
102-
<dependency>
103-
<groupId>org.skyscreamer</groupId>
104-
<artifactId>jsonassert</artifactId>
105-
<version>1.5.3</version>
106-
<scope>test</scope>
107-
</dependency>
108-
</dependencies>
75+
<dependency>
76+
<groupId>com.fasterxml.jackson.core</groupId>
77+
<artifactId>jackson-databind</artifactId>
78+
<version>${jackson.version}</version>
79+
<scope>test</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>com.fasterxml.jackson.module</groupId>
83+
<artifactId>jackson-module-parameter-names</artifactId>
84+
<version>${jackson.version}</version>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.fasterxml.jackson.datatype</groupId>
89+
<artifactId>jackson-datatype-jdk8</artifactId>
90+
<version>${jackson.version}</version>
91+
<scope>test</scope>
92+
</dependency>
93+
<dependency>
94+
<groupId>com.fasterxml.jackson.datatype</groupId>
95+
<artifactId>jackson-datatype-jsr310</artifactId>
96+
<version>${jackson.version}</version>
97+
<scope>test</scope>
98+
</dependency>
99+
<dependency>
100+
<groupId>io.reactivex.rxjava3</groupId>
101+
<artifactId>rxjava</artifactId>
102+
<version>3.1.10</version>
103+
<scope>test</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>org.junit.jupiter</groupId>
107+
<artifactId>junit-jupiter</artifactId>
108+
<version>${junit.jupiter.version}</version>
109+
<scope>test</scope>
110+
</dependency>
111+
<dependency>
112+
<groupId>org.skyscreamer</groupId>
113+
<artifactId>jsonassert</artifactId>
114+
<version>1.5.3</version>
115+
<scope>test</scope>
116+
</dependency>
117+
</dependencies>
109118
</project>

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/DirectiveProcessor.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313

1414
import com.phocassoftware.graphql.builder.annotations.Directive;
1515
import graphql.introspection.Introspection;
16-
import graphql.schema.*;
16+
import graphql.schema.GraphQLAppliedDirective;
17+
import graphql.schema.GraphQLAppliedDirectiveArgument;
18+
import graphql.schema.GraphQLArgument;
19+
import graphql.schema.GraphQLDirective;
20+
1721
import java.lang.annotation.Annotation;
1822
import java.lang.reflect.InvocationTargetException;
1923
import java.lang.reflect.Method;
20-
import java.util.*;
24+
import java.util.HashMap;
25+
import java.util.Map;
2126
import java.util.function.Consumer;
2227
import java.util.function.Function;
2328

@@ -31,17 +36,26 @@ public DirectiveProcessor(GraphQLDirective directive, Map<String, Function<Objec
3136
this.builders = builders;
3237
}
3338

34-
public static DirectiveProcessor build(EntityProcessor entityProcessor, Class<? extends Annotation> directive) {
39+
public static DirectiveProcessor build(EntityProcessor entityProcessor, Class<? extends Annotation> directive, boolean isJakarta) {
3540
var builder = GraphQLDirective.newDirective().name(directive.getSimpleName());
36-
var validLocations = directive.getAnnotation(Directive.class).value();
41+
42+
Introspection.DirectiveLocation[] validLocations;
43+
if (isJakarta) {
44+
validLocations = new Introspection.DirectiveLocation[] {
45+
Introspection.DirectiveLocation.ARGUMENT_DEFINITION,
46+
Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION };
47+
} else {
48+
validLocations = directive.getAnnotation(Directive.class).value();
49+
50+
// Check for repeatable tag in annotation and add it
51+
builder.repeatable(directive.getAnnotation(Directive.class).repeatable());
52+
}
53+
3754
// loop through and add valid locations
3855
for (Introspection.DirectiveLocation location : validLocations) {
3956
builder.validLocation(location);
4057
}
4158

42-
// Check for repeatable tag in annotation and add it
43-
builder.repeatable(directive.getAnnotation(Directive.class).repeatable());
44-
4559
// Go through each argument and add name/type to directive
4660
var methods = directive.getDeclaredMethods();
4761
Map<String, Function<Object, GraphQLAppliedDirectiveArgument>> builders = new HashMap<>();

0 commit comments

Comments
 (0)