Skip to content

Commit 48032c6

Browse files
authored
Merge pull request #31501 from mskacelik/smallrye-graphQL-2.1.1
Update SmallRye GraphQL to 2.1.1
2 parents 0b8cb81 + ca06329 commit 48032c6

File tree

7 files changed

+174
-1
lines changed

7 files changed

+174
-1
lines changed

bom/application/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<smallrye-health.version>4.0.1</smallrye-health.version>
6060
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
6161
<smallrye-open-api.version>3.2.0</smallrye-open-api.version>
62-
<smallrye-graphql.version>2.1.0</smallrye-graphql.version>
62+
<smallrye-graphql.version>2.1.1</smallrye-graphql.version>
6363
<smallrye-opentracing.version>3.0.3</smallrye-opentracing.version>
6464
<smallrye-fault-tolerance.version>6.2.0</smallrye-fault-tolerance.version>
6565
<smallrye-jwt.version>4.2.0</smallrye-jwt.version>

extensions/smallrye-graphql-client/deployment/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
<artifactId>quarkus-smallrye-graphql-deployment</artifactId>
5454
<scope>test</scope>
5555
</dependency>
56+
<dependency>
57+
<groupId>io.quarkus</groupId>
58+
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
59+
<scope>test</scope>
60+
</dependency>
5661
<dependency>
5762
<groupId>io.smallrye.stork</groupId>
5863
<artifactId>stork-service-discovery-static-list</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package io.quarkus.smallrye.graphql.client.deployment;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import jakarta.inject.Inject;
6+
import jakarta.ws.rs.Consumes;
7+
import jakarta.ws.rs.POST;
8+
import jakarta.ws.rs.Path;
9+
import jakarta.ws.rs.Produces;
10+
11+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
12+
import org.jboss.shrinkwrap.api.asset.StringAsset;
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.extension.RegisterExtension;
15+
16+
import io.quarkus.test.QuarkusUnitTest;
17+
import io.smallrye.graphql.client.GraphQLClient;
18+
import io.smallrye.graphql.client.Response;
19+
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;
20+
21+
/**
22+
* This test verifies that if <code>quarkus.smallrye-graphql-client.CLIENT_NAME.allow-unexpected-response-fields=true</code>
23+
* is set, then the client , instead of throwing an exception, logs a warning if it receives an unexpected top-level
24+
* field in a response.
25+
*/
26+
public class GraphQLClientUnexpectedFieldsTest {
27+
28+
static String url = "http://" + System.getProperty("quarkus.http.host", "localhost") + ":"
29+
+ System.getProperty("quarkus.http.test-port", "8081") + "/invalid-graphql-endpoint";
30+
31+
@RegisterExtension
32+
static QuarkusUnitTest test = new QuarkusUnitTest()
33+
.withApplicationRoot((jar) -> jar
34+
.addAsResource(
35+
new StringAsset(
36+
"quarkus.smallrye-graphql-client.client1.url=" + url + "\n" +
37+
"quarkus.smallrye-graphql-client.client1.allow-unexpected-response-fields=true\n"),
38+
"application.properties")
39+
.addClass(MockGraphQLEndpoint.class)
40+
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
41+
42+
@Path("/invalid-graphql-endpoint")
43+
@Produces("application/json+graphql")
44+
@Consumes("application/json")
45+
public static class MockGraphQLEndpoint {
46+
@POST
47+
public String returnInvalidResponse() {
48+
return "{\n" +
49+
" \"data\": {\n" +
50+
" \"number\": 32\n" +
51+
" },\n" +
52+
" \"bugs\": {\n" +
53+
" }\n" +
54+
"}";
55+
}
56+
}
57+
58+
@Inject
59+
@GraphQLClient("client1")
60+
DynamicGraphQLClient client;
61+
62+
@Test
63+
public void ignoringUnexpectedResponseField() throws Exception {
64+
Response response = client.executeSync("query {something}}");
65+
assertEquals(32, response.getObject(Long.class, "number"));
66+
}
67+
}

extensions/smallrye-graphql-client/runtime/src/main/java/io/quarkus/smallrye/graphql/client/runtime/GraphQLClientConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,12 @@ public class GraphQLClientConfig {
119119
*/
120120
@ConfigItem(name = "init-payload")
121121
public Map<String, String> initPayload;
122+
123+
/**
124+
* Allowing unexpected fields in response.
125+
* If true, there will be warning log of an unexpected field.
126+
* Else it throws an error.
127+
*/
128+
@ConfigItem
129+
public Optional<Boolean> allowUnexpectedResponseFields;
122130
}

extensions/smallrye-graphql-client/runtime/src/main/java/io/quarkus/smallrye/graphql/client/runtime/GraphQLClientConfigurationMergerBean.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ private GraphQLClientConfiguration toSmallRyeNativeConfiguration(GraphQLClientCo
114114
quarkusConfig.executeSingleResultOperationsOverWebsocket
115115
.ifPresent(transformed::setExecuteSingleOperationsOverWebsocket);
116116
quarkusConfig.websocketInitializationTimeout.ifPresent(transformed::setWebsocketInitializationTimeout);
117+
quarkusConfig.allowUnexpectedResponseFields.ifPresent(transformed::setAllowUnexpectedResponseFields);
117118
return transformed;
118119
}
119120

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import io.quarkus.vertx.http.deployment.webjar.WebJarResourcesFilter;
7272
import io.quarkus.vertx.http.deployment.webjar.WebJarResultsBuildItem;
7373
import io.smallrye.graphql.api.AdaptWith;
74+
import io.smallrye.graphql.api.Deprecated;
7475
import io.smallrye.graphql.api.Entry;
7576
import io.smallrye.graphql.api.ErrorExtensionProvider;
7677
import io.smallrye.graphql.api.federation.Extends;
@@ -264,6 +265,7 @@ void buildFinalIndex(
264265
indexer.indexClass(Key.class);
265266
indexer.indexClass(Provides.class);
266267
indexer.indexClass(Requires.class);
268+
indexer.indexClass(Deprecated.class);
267269
} catch (IOException ex) {
268270
LOG.warn("Failure while creating index", ex);
269271
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package io.quarkus.smallrye.graphql.deployment;
2+
3+
import static io.restassured.RestAssured.get;
4+
import static org.hamcrest.Matchers.containsString;
5+
6+
import org.eclipse.microprofile.graphql.GraphQLApi;
7+
import org.eclipse.microprofile.graphql.Query;
8+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
9+
import org.jboss.shrinkwrap.api.asset.StringAsset;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
import io.quarkus.test.QuarkusUnitTest;
14+
import io.smallrye.graphql.api.Deprecated;
15+
16+
public class DeprecatedGraphQLDirectivesTest extends AbstractGraphQLTest {
17+
18+
@RegisterExtension
19+
static QuarkusUnitTest test = new QuarkusUnitTest()
20+
.withApplicationRoot((jar) -> jar
21+
.addClasses(Person.class)
22+
.addAsResource(new StringAsset("quarkus.smallrye-graphql.schema-include-directives=true"),
23+
"application.properties")
24+
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
25+
26+
@Test
27+
public void deprecatedDirectivesPresentInSchema() {
28+
get("/graphql/schema.graphql")
29+
.then()
30+
.body(containsString("input PersonInput {\n" +
31+
" age: Int! @deprecated\n" +
32+
" name: String @deprecated(reason : \"reason0\")\n" +
33+
" numberOfEyes: BigInteger! @deprecated\n" +
34+
"}\n"))
35+
.body(containsString(
36+
"queryWithDeprecatedArgument(deprecated: String @deprecated(reason : \"reason1\")): String"));
37+
}
38+
39+
@GraphQLApi
40+
public static class ValidationApi {
41+
42+
@Query
43+
public String query(Person person) {
44+
return null;
45+
}
46+
47+
@Query
48+
public String queryWithDeprecatedArgument(@Deprecated(reason = "reason1") String deprecated) {
49+
return null;
50+
}
51+
52+
}
53+
54+
public static class Person {
55+
56+
@Deprecated(reason = "reason0")
57+
private String name;
58+
59+
@java.lang.Deprecated
60+
private int age;
61+
62+
@Deprecated
63+
private long numberOfEyes;
64+
65+
public String getName() {
66+
return name;
67+
}
68+
69+
public void setName(String name) {
70+
this.name = name;
71+
}
72+
73+
public int getAge() {
74+
return age;
75+
}
76+
77+
public void setAge(int age) {
78+
this.age = age;
79+
}
80+
81+
public long getNumberOfEyes() {
82+
return numberOfEyes;
83+
}
84+
85+
public void setNumberOfEyes(long numberOfEyes) {
86+
this.numberOfEyes = numberOfEyes;
87+
}
88+
}
89+
90+
}

0 commit comments

Comments
 (0)