Skip to content

Commit

Permalink
Merge pull request #102 from bclozel/graphql-java
Browse files Browse the repository at this point in the history
Add support for GraphQL Java 19.2
  • Loading branch information
dnestoro authored Nov 16, 2022
2 parents 4ca6fe0 + d885d19 commit f200d19
Show file tree
Hide file tree
Showing 19 changed files with 394 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metadata/com.graphql-java/graphql-java/19.2/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"reflect-config.json",
"resource-config.json"
]
44 changes: 44 additions & 0 deletions metadata/com.graphql-java/graphql-java/19.2/reflect-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"name": "graphql.schema.GraphQLArgument",
"allPublicMethods": true,
"condition": {
"typeReachable": "graphql.GraphQL"
}
},
{
"name": "graphql.schema.GraphQLDirective",
"allPublicMethods": true,
"condition": {
"typeReachable": "graphql.GraphQL"
}
},
{
"name": "graphql.schema.GraphQLEnumValueDefinition",
"allPublicMethods": true,
"condition": {
"typeReachable": "graphql.GraphQL"
}
},
{
"name": "graphql.schema.GraphQLFieldDefinition",
"allPublicMethods": true,
"condition": {
"typeReachable": "graphql.GraphQL"
}
},
{
"name": "graphql.schema.GraphQLInputObjectField",
"allPublicMethods": true,
"condition": {
"typeReachable": "graphql.GraphQL"
}
},
{
"name": "graphql.schema.GraphQLOutputType",
"allPublicMethods": true,
"condition": {
"typeReachable": "graphql.GraphQL"
}
}
]
19 changes: 19 additions & 0 deletions metadata/com.graphql-java/graphql-java/19.2/resource-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bundles": [
{
"name": "i18n.General"
},
{
"name": "i18n.Parsing"
},
{
"name": "i18n.Scalars"
},
{
"name": "i18n.Validation"
}
],
"resources": {
"includes": []
}
}
10 changes: 10 additions & 0 deletions metadata/com.graphql-java/graphql-java/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"latest": true,
"metadata-version": "19.2",
"module": "com.graphql-java:graphql-java",
"tested-versions": [
"19.2"
]
}
]
4 changes: 4 additions & 0 deletions metadata/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,9 @@
{
"directory": "org.jboss.logging/jboss-logging",
"module": "org.jboss.logging:jboss-logging"
},
{
"directory": "com.graphql-java/graphql-java",
"module": "com.graphql-java:graphql-java"
}
]
4 changes: 4 additions & 0 deletions tests/src/com.graphql-java/graphql-java/19.2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gradlew.bat
gradlew
gradle/
build/
20 changes: 20 additions & 0 deletions tests/src/com.graphql-java/graphql-java/19.2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

import org.graalvm.internal.tck.TestUtils

plugins {
id "org.graalvm.internal.tck"
}

String libraryVersion = TestUtils.testedLibraryVersion

dependencies {
testImplementation "com.graphql-java:graphql-java:$libraryVersion"
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.awaitility:awaitility:4.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library.version = 19.2
metadata.dir = com.graphql-java/graphql-java/19.2/
13 changes: 13 additions & 0 deletions tests/src/com.graphql-java/graphql-java/19.2/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pluginManagement {
def tckPath = Objects.requireNonNullElse(
System.getenv("GVM_TCK_TCKDIR"),
"../../../../tck-build-logic"
)
includeBuild(tckPath)
}

plugins {
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT"
}

rootProject.name = 'graphql-java-tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package graphql;

import java.io.IOException;
import java.io.InputStream;
import java.util.function.Consumer;

import graphql.introspection.IntrospectionQuery;
import graphql.schema.GraphQLSchema;
import graphql.schema.StaticDataFetcher;
import graphql.schema.TypeResolver;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import graphql.starwars.Droid;
import graphql.starwars.Human;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Brian Clozel
*/
public class GraphQlTests {


@Test
void greetingQuery() throws Exception {
GraphQLSchema graphQLSchema = parseSchema("greeting", runtimeWiringBuilder ->
runtimeWiringBuilder.type("Query", builder ->
builder.dataFetcher("greeting", new StaticDataFetcher("Hello GraphQL"))));
GraphQL graphQl = GraphQL.newGraphQL(graphQLSchema).build();
ExecutionResult result = graphQl.execute("{ greeting }");
assertThat(result.getErrors()).isEmpty();
assertThat(result.getData().toString()).isEqualTo("{greeting=Hello GraphQL}");
}

@Test
void introspectionQuery() throws Exception {
GraphQLSchema graphQLSchema = parseSchema("starwars", runtimeWiringBuilder -> {
runtimeWiringBuilder.type("Query", builder -> builder.typeName("Character").typeResolver(characterTypeResolver()));
});
GraphQL graphQl = GraphQL.newGraphQL(graphQLSchema).build();
ExecutionResult result = graphQl.execute(IntrospectionQuery.INTROSPECTION_QUERY);
assertThat(result.getErrors()).isEmpty();
assertThat(result.getData().toString()).contains("{__schema={queryType={name=QueryType}");
}

private GraphQLSchema parseSchema(String schemaFileName, Consumer<RuntimeWiring.Builder> consumer) throws IOException {
try (InputStream inputStream = GraphQlTests.class.getResourceAsStream(schemaFileName + ".graphqls")) {
TypeDefinitionRegistry registry = new SchemaParser().parse(inputStream);
RuntimeWiring.Builder runtimeWiringBuilder = RuntimeWiring.newRuntimeWiring();
consumer.accept(runtimeWiringBuilder);
return new SchemaGenerator().makeExecutableSchema(registry, runtimeWiringBuilder.build());
}
}

private TypeResolver characterTypeResolver() {
return env -> {
Object javaObject = env.getObject();
if (javaObject instanceof Droid) {
return env.getSchema().getObjectType("Droid");
} else if (javaObject instanceof Human) {
return env.getSchema().getObjectType("Human");
} else {
throw new IllegalStateException("Unknown Character type");
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package graphql.starwars;

import java.util.List;

/**
* @author Brian Clozel
*/
public interface Character {

Long getId();

String getName();

Character getFriends();

List<Episode> getAppearsIn();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package graphql.starwars;

import java.util.List;

/**
* @author Brian Clozel
*/
public class Droid implements Character {

@Override
public Long getId() {
return null;
}

@Override
public String getName() {
return null;
}

@Override
public Character getFriends() {
return null;
}

@Override
public List<Episode> getAppearsIn() {
return null;
}

public String getPrimaryFunction() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package graphql.starwars;

/**
* @author Brian Clozel
*/
public enum Episode {
NEWHOPE,
EMPIRE,
JEDI
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package graphql.starwars;

import java.util.List;

/**
* @author Brian Clozel
*/
public class Human implements Character {

@Override
public Long getId() {
return null;
}

@Override
public String getName() {
return null;
}

@Override
public Character getFriends() {
return null;
}

@Override
public List<Episode> getAppearsIn() {
return null;
}

public String getHomePlanet() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bundles": [],
"resources": {
"includes": [
{
"pattern": "\\Qgraphql/greeting.graphqls\\E",
"condition": {
"typeReachable": "graphql.GraphQL"
}
},
{
"pattern": "\\Qgraphql/starwars.graphqls\\E",
"condition": {
"typeReachable": "graphql.GraphQL"
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Query {
greeting: String
}
Loading

0 comments on commit f200d19

Please sign in to comment.