Skip to content

Commit 61d3986

Browse files
authored
Merge pull request quarkusio#36348 from jmartisk/smallrye-graphql-2.5.0
Smallrye GraphQL 2.5.0
2 parents 798dba7 + bba3785 commit 61d3986

File tree

13 files changed

+412
-6
lines changed

13 files changed

+412
-6
lines changed

bom/application/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<micrometer.version>1.11.1</micrometer.version><!-- keep in sync with hdrhistogram -->
3939
<hdrhistogram.version>2.1.12</hdrhistogram.version><!-- keep in sync with micrometer -->
4040
<google-auth.version>0.22.0</google-auth.version>
41-
<graphql-java.version>20.2</graphql-java.version> <!-- keep in sync with smallrye-graphql -->
41+
<graphql-java.version>21.1</graphql-java.version> <!-- keep in sync with smallrye-graphql -->
4242
<microprofile-config-api.version>3.0.3</microprofile-config-api.version>
4343
<microprofile-health-api.version>4.0.1</microprofile-health-api.version>
4444
<microprofile-metrics-api.version>4.0.1</microprofile-metrics-api.version>
@@ -55,7 +55,7 @@
5555
<smallrye-health.version>4.0.4</smallrye-health.version>
5656
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
5757
<smallrye-open-api.version>3.6.2</smallrye-open-api.version>
58-
<smallrye-graphql.version>2.4.0</smallrye-graphql.version>
58+
<smallrye-graphql.version>2.5.0</smallrye-graphql.version>
5959
<smallrye-opentracing.version>3.0.3</smallrye-opentracing.version>
6060
<smallrye-fault-tolerance.version>6.2.6</smallrye-fault-tolerance.version>
6161
<smallrye-jwt.version>4.3.1</smallrye-jwt.version>

extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,16 @@ void activateEventing(SmallRyeGraphQLConfig graphQLConfig, BuildProducer<SystemP
652652
}
653653
}
654654

655+
@BuildStep
656+
void activateFederationBatchResolving(SmallRyeGraphQLConfig graphQLConfig,
657+
BuildProducer<SystemPropertyBuildItem> systemProperties) {
658+
if (graphQLConfig.federationBatchResolvingEnabled.isPresent()) {
659+
String value = graphQLConfig.federationBatchResolvingEnabled.get().toString();
660+
systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_FEDERATION_BATCH_RESOLVING, value));
661+
System.setProperty(ConfigKey.ENABLE_FEDERATION_BATCH_RESOLVING, value);
662+
}
663+
}
664+
655665
/*
656666
* Decides whether we want to activate GraphQL federation and updates system properties accordingly.
657667
* If quarkus.smallrye-graphql.federation.enabled is unspecified, enable federation automatically if we see
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.quarkus.smallrye.graphql.deployment.federation.batch;
2+
3+
import io.smallrye.graphql.api.federation.Extends;
4+
import io.smallrye.graphql.api.federation.External;
5+
import io.smallrye.graphql.api.federation.Key;
6+
7+
@Key(fields = "id")
8+
@Extends
9+
public class Foo {
10+
11+
@External
12+
public int id;
13+
14+
public String name;
15+
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.quarkus.smallrye.graphql.deployment.federation.batch;
2+
3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
6+
import org.eclipse.microprofile.graphql.GraphQLApi;
7+
import org.eclipse.microprofile.graphql.Query;
8+
9+
@GraphQLApi
10+
public class FooApi {
11+
@Query
12+
public List<Foo> foos(List<Integer> id) {
13+
return id.stream().map(this::foo).collect(Collectors.toList());
14+
}
15+
16+
private Foo foo(int id) {
17+
var foo = new Foo();
18+
foo.id = id;
19+
foo.name = "Name of " + id;
20+
return foo;
21+
}
22+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.quarkus.smallrye.graphql.deployment.federation.batch;
2+
3+
import static org.hamcrest.Matchers.containsString;
4+
5+
import org.hamcrest.CoreMatchers;
6+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
7+
import org.jboss.shrinkwrap.api.asset.StringAsset;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.RegisterExtension;
10+
11+
import io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest;
12+
import io.quarkus.test.QuarkusUnitTest;
13+
import io.restassured.RestAssured;
14+
15+
public class GraphQLFederationBatchTest extends AbstractGraphQLTest {
16+
17+
@RegisterExtension
18+
static QuarkusUnitTest test = new QuarkusUnitTest()
19+
.withApplicationRoot((jar) -> jar
20+
.addClasses(FooApi.class, Foo.class)
21+
.addAsResource(new StringAsset("quarkus.smallrye-graphql.schema-include-directives=true\n" +
22+
"quarkus.smallrye-graphql.federation.batch-resolving-enabled=true"),
23+
"application.properties")
24+
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
25+
26+
@Test
27+
public void checkServiceDeclarationInSchema() {
28+
RestAssured.given()
29+
.get("/graphql/schema.graphql")
30+
.then()
31+
.body(containsString("type _Service {"));
32+
}
33+
34+
@Test
35+
public void checkFederationDirectivesInSchema() {
36+
RestAssured.given()
37+
.get("/graphql/schema.graphql")
38+
.then()
39+
.body(containsString("id: Int! @external"))
40+
.body(containsString("type Foo @extends @key(fields : \"id\")"));
41+
;
42+
}
43+
44+
@Test
45+
public void resolvePerFederation() {
46+
String query = "query federation($representations: [_Any!]!) {\n" +
47+
" _entities(representations: $representations) {\n" +
48+
" ... on Foo {\n" +
49+
" id\n" +
50+
" name\n" +
51+
" }\n" +
52+
" }\n" +
53+
"}";
54+
String variables = "{\n" +
55+
" \"representations\": [\n" +
56+
" {\n" +
57+
" \"__typename\": \"Foo\",\n" +
58+
" \"id\": 1\n" +
59+
" },\n" +
60+
" {\n" +
61+
" \"__typename\": \"Foo\",\n" +
62+
" \"id\": 2\n" +
63+
" }\n" +
64+
" ]\n" +
65+
"}";
66+
67+
String request = getPayload(query, variables);
68+
RestAssured.given().when()
69+
.accept(MEDIATYPE_JSON)
70+
.contentType(MEDIATYPE_JSON)
71+
.body(request)
72+
.post("/graphql")
73+
.then()
74+
.assertThat()
75+
.statusCode(200)
76+
.and()
77+
.body(CoreMatchers.is(
78+
"{\"data\":{\"_entities\":[{\"id\":1,\"name\":\"Name of 1\"},{\"id\":2,\"name\":\"Name of 2\"}]}}"));
79+
}
80+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.quarkus.smallrye.graphql.deployment.federation.batch.uni;
2+
3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
6+
import org.eclipse.microprofile.graphql.GraphQLApi;
7+
import org.eclipse.microprofile.graphql.Query;
8+
9+
import io.quarkus.smallrye.graphql.deployment.federation.batch.Foo;
10+
import io.smallrye.mutiny.Uni;
11+
12+
@GraphQLApi
13+
public class FooApiUni {
14+
15+
@Query
16+
public Uni<List<Foo>> foos(List<Integer> id) {
17+
return Uni.join().all(id.stream().map(this::foo).collect(Collectors.toList())).andFailFast();
18+
}
19+
20+
private Uni<Foo> foo(int id) {
21+
var foo = new Foo();
22+
foo.id = id;
23+
foo.name = "Name of " + id;
24+
return Uni.createFrom().item(foo);
25+
}
26+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package io.quarkus.smallrye.graphql.deployment.federation.batch.uni;
2+
3+
import static org.hamcrest.Matchers.containsString;
4+
5+
import org.hamcrest.CoreMatchers;
6+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
7+
import org.jboss.shrinkwrap.api.asset.StringAsset;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.RegisterExtension;
10+
11+
import io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest;
12+
import io.quarkus.smallrye.graphql.deployment.federation.batch.Foo;
13+
import io.quarkus.test.QuarkusUnitTest;
14+
import io.restassured.RestAssured;
15+
16+
public class GraphQLFederationBatchUniTest extends AbstractGraphQLTest {
17+
18+
@RegisterExtension
19+
static QuarkusUnitTest test = new QuarkusUnitTest()
20+
.withApplicationRoot((jar) -> jar
21+
.addClasses(FooApiUni.class, Foo.class)
22+
.addAsResource(new StringAsset("quarkus.smallrye-graphql.schema-include-directives=true\n" +
23+
"quarkus.smallrye-graphql.federation.batch-resolving-enabled=true"),
24+
"application.properties")
25+
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
26+
27+
@Test
28+
public void checkServiceDeclarationInSchema() {
29+
RestAssured.given()
30+
.get("/graphql/schema.graphql")
31+
.then()
32+
.body(containsString("type _Service {"));
33+
}
34+
35+
@Test
36+
public void checkFederationDirectivesInSchema() {
37+
RestAssured.given()
38+
.get("/graphql/schema.graphql")
39+
.then()
40+
.body(containsString("id: Int! @external"))
41+
.body(containsString("type Foo @extends @key(fields : \"id\")"));
42+
;
43+
}
44+
45+
@Test
46+
public void resolvePerFederation() {
47+
String query = "query federation($representations: [_Any!]!) {\n" +
48+
" _entities(representations: $representations) {\n" +
49+
" ... on Foo {\n" +
50+
" id\n" +
51+
" name\n" +
52+
" }\n" +
53+
" }\n" +
54+
"}";
55+
String variables = "{\n" +
56+
" \"representations\": [\n" +
57+
" {\n" +
58+
" \"__typename\": \"Foo\",\n" +
59+
" \"id\": 1\n" +
60+
" },\n" +
61+
" {\n" +
62+
" \"__typename\": \"Foo\",\n" +
63+
" \"id\": 2\n" +
64+
" }\n" +
65+
" ]\n" +
66+
"}";
67+
68+
String request = getPayload(query, variables);
69+
RestAssured.given().when()
70+
.accept(MEDIATYPE_JSON)
71+
.contentType(MEDIATYPE_JSON)
72+
.body(request)
73+
.post("/graphql")
74+
.then()
75+
.assertThat()
76+
.statusCode(200)
77+
.and()
78+
.body(CoreMatchers.is(
79+
"{\"data\":{\"_entities\":[{\"id\":1,\"name\":\"Name of 1\"},{\"id\":2,\"name\":\"Name of 2\"}]}}"));
80+
}
81+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.quarkus.smallrye.graphql.deployment.federation.complex;
2+
3+
import io.smallrye.graphql.api.federation.Extends;
4+
import io.smallrye.graphql.api.federation.External;
5+
import io.smallrye.graphql.api.federation.Key;
6+
7+
@Key(fields = "id")
8+
@Key(fields = "otherId")
9+
@Extends
10+
public class Bar {
11+
12+
@External
13+
public int id;
14+
@External
15+
public String otherId;
16+
17+
public String name;
18+
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.quarkus.smallrye.graphql.deployment.federation.complex;
2+
3+
import io.smallrye.graphql.api.federation.Extends;
4+
import io.smallrye.graphql.api.federation.External;
5+
import io.smallrye.graphql.api.federation.Key;
6+
7+
@Key(fields = "id")
8+
@Extends
9+
public class Foo {
10+
11+
@External
12+
public int id;
13+
14+
public String name;
15+
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.quarkus.smallrye.graphql.deployment.federation.complex;
2+
3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
import java.util.stream.IntStream;
6+
7+
import org.eclipse.microprofile.graphql.GraphQLApi;
8+
import org.eclipse.microprofile.graphql.Query;
9+
10+
import io.smallrye.mutiny.Uni;
11+
12+
@GraphQLApi
13+
public class FooApi {
14+
@Query
15+
public Foo foo(int id) {
16+
var foo = new Foo();
17+
foo.id = id;
18+
foo.name = "Name of " + id;
19+
return foo;
20+
}
21+
22+
@Query
23+
public Uni<List<Bar>> bars(List<Integer> id, List<String> otherId) {
24+
return Uni.join().all(
25+
IntStream.range(0, id.size()).boxed().map(i -> bar(id.get(i), otherId.get(i))).collect(Collectors.toList()))
26+
.andFailFast();
27+
}
28+
29+
private Uni<Bar> bar(int id, String otherId) {
30+
var bar = new Bar();
31+
bar.id = id;
32+
bar.otherId = otherId;
33+
bar.name = id + otherId;
34+
return Uni.createFrom().item(bar);
35+
}
36+
}

0 commit comments

Comments
 (0)