Skip to content

Commit 3f62d86

Browse files
committed
Add support for GraphQL Java 19.2
This commit adds reachability metadata for the GraphQL Java project. Tests involve a simple query to trigger the base infrastructure. Since GraphQL Java will perform reflection mostly on user provided types, tests also use a complete introspection query on a complex schema to trigger reflection on GraphQL Java types.
1 parent bf58a4c commit 3f62d86

File tree

19 files changed

+394
-0
lines changed

19 files changed

+394
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
"reflect-config.json",
3+
"resource-config.json"
4+
]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
"name": "graphql.schema.GraphQLArgument",
4+
"allPublicMethods": true,
5+
"condition": {
6+
"typeReachable": "graphql.GraphQL"
7+
}
8+
},
9+
{
10+
"name": "graphql.schema.GraphQLDirective",
11+
"allPublicMethods": true,
12+
"condition": {
13+
"typeReachable": "graphql.GraphQL"
14+
}
15+
},
16+
{
17+
"name": "graphql.schema.GraphQLEnumValueDefinition",
18+
"allPublicMethods": true,
19+
"condition": {
20+
"typeReachable": "graphql.GraphQL"
21+
}
22+
},
23+
{
24+
"name": "graphql.schema.GraphQLFieldDefinition",
25+
"allPublicMethods": true,
26+
"condition": {
27+
"typeReachable": "graphql.GraphQL"
28+
}
29+
},
30+
{
31+
"name": "graphql.schema.GraphQLInputObjectField",
32+
"allPublicMethods": true,
33+
"condition": {
34+
"typeReachable": "graphql.GraphQL"
35+
}
36+
},
37+
{
38+
"name": "graphql.schema.GraphQLOutputType",
39+
"allPublicMethods": true,
40+
"condition": {
41+
"typeReachable": "graphql.GraphQL"
42+
}
43+
}
44+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"bundles": [
3+
{
4+
"name": "i18n.General"
5+
},
6+
{
7+
"name": "i18n.Parsing"
8+
},
9+
{
10+
"name": "i18n.Scalars"
11+
},
12+
{
13+
"name": "i18n.Validation"
14+
}
15+
],
16+
"resources": {
17+
"includes": []
18+
}
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"latest": true,
4+
"metadata-version": "19.2",
5+
"module": "com.graphql-java:graphql-java",
6+
"tested-versions": [
7+
"19.2"
8+
]
9+
}
10+
]

metadata/index.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,9 @@
126126
{
127127
"directory": "org.liquibase/liquibase-core",
128128
"module": "org.liquibase:liquibase-core"
129+
},
130+
{
131+
"directory": "com.graphql-java/graphql-java",
132+
"module": "com.graphql-java:graphql-java"
129133
}
130134
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
gradlew.bat
2+
gradlew
3+
gradle/
4+
build/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
8+
import org.graalvm.internal.tck.TestUtils
9+
10+
plugins {
11+
id "org.graalvm.internal.tck"
12+
}
13+
14+
String libraryVersion = TestUtils.testedLibraryVersion
15+
16+
dependencies {
17+
testImplementation "com.graphql-java:graphql-java:$libraryVersion"
18+
testImplementation 'org.assertj:assertj-core:3.22.0'
19+
testImplementation 'org.awaitility:awaitility:4.2.0'
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
library.version = 19.2
2+
metadata.dir = com.graphql-java/graphql-java/19.2/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pluginManagement {
2+
def tckPath = Objects.requireNonNullElse(
3+
System.getenv("GVM_TCK_TCKDIR"),
4+
"../../../../tck-build-logic"
5+
)
6+
includeBuild(tckPath)
7+
}
8+
9+
plugins {
10+
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT"
11+
}
12+
13+
rootProject.name = 'graphql-java-tests'
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
package graphql;
8+
9+
import java.io.IOException;
10+
import java.io.InputStream;
11+
import java.util.function.Consumer;
12+
13+
import graphql.introspection.IntrospectionQuery;
14+
import graphql.schema.GraphQLSchema;
15+
import graphql.schema.StaticDataFetcher;
16+
import graphql.schema.TypeResolver;
17+
import graphql.schema.idl.RuntimeWiring;
18+
import graphql.schema.idl.SchemaGenerator;
19+
import graphql.schema.idl.SchemaParser;
20+
import graphql.schema.idl.TypeDefinitionRegistry;
21+
import graphql.starwars.Droid;
22+
import graphql.starwars.Human;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* @author Brian Clozel
29+
*/
30+
public class GraphQlTests {
31+
32+
33+
@Test
34+
void greetingQuery() throws Exception {
35+
GraphQLSchema graphQLSchema = parseSchema("greeting", runtimeWiringBuilder ->
36+
runtimeWiringBuilder.type("Query", builder ->
37+
builder.dataFetcher("greeting", new StaticDataFetcher("Hello GraphQL"))));
38+
GraphQL graphQl = GraphQL.newGraphQL(graphQLSchema).build();
39+
ExecutionResult result = graphQl.execute("{ greeting }");
40+
assertThat(result.getErrors()).isEmpty();
41+
assertThat(result.getData().toString()).isEqualTo("{greeting=Hello GraphQL}");
42+
}
43+
44+
@Test
45+
void introspectionQuery() throws Exception {
46+
GraphQLSchema graphQLSchema = parseSchema("starwars", runtimeWiringBuilder -> {
47+
runtimeWiringBuilder.type("Query", builder -> builder.typeName("Character").typeResolver(characterTypeResolver()));
48+
});
49+
GraphQL graphQl = GraphQL.newGraphQL(graphQLSchema).build();
50+
ExecutionResult result = graphQl.execute(IntrospectionQuery.INTROSPECTION_QUERY);
51+
assertThat(result.getErrors()).isEmpty();
52+
assertThat(result.getData().toString()).contains("{__schema={queryType={name=QueryType}");
53+
}
54+
55+
private GraphQLSchema parseSchema(String schemaFileName, Consumer<RuntimeWiring.Builder> consumer) throws IOException {
56+
try (InputStream inputStream = GraphQlTests.class.getResourceAsStream(schemaFileName + ".graphqls")) {
57+
TypeDefinitionRegistry registry = new SchemaParser().parse(inputStream);
58+
RuntimeWiring.Builder runtimeWiringBuilder = RuntimeWiring.newRuntimeWiring();
59+
consumer.accept(runtimeWiringBuilder);
60+
return new SchemaGenerator().makeExecutableSchema(registry, runtimeWiringBuilder.build());
61+
}
62+
}
63+
64+
private TypeResolver characterTypeResolver() {
65+
return env -> {
66+
Object javaObject = env.getObject();
67+
if (javaObject instanceof Droid) {
68+
return env.getSchema().getObjectType("Droid");
69+
} else if (javaObject instanceof Human) {
70+
return env.getSchema().getObjectType("Human");
71+
} else {
72+
throw new IllegalStateException("Unknown Character type");
73+
}
74+
};
75+
}
76+
77+
}

0 commit comments

Comments
 (0)