From 8b5bcd1196b3b8f1b24d6312bc3a71ce4252e4f6 Mon Sep 17 00:00:00 2001 From: Marek Skacelik Date: Mon, 11 Nov 2024 14:44:53 +0100 Subject: [PATCH 1/2] removed unnecessary "data": null if request failed before execution (via GraphQL specification) --- .../graphql/execution/ExecutionResponse.java | 3 +++ .../tests/customscalars/CustomScalarTest.java | 6 +++--- .../tests/error/UnparseableDocumentTestCase.java | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/implementation/src/main/java/io/smallrye/graphql/execution/ExecutionResponse.java b/server/implementation/src/main/java/io/smallrye/graphql/execution/ExecutionResponse.java index a40e53f19..308553aae 100644 --- a/server/implementation/src/main/java/io/smallrye/graphql/execution/ExecutionResponse.java +++ b/server/implementation/src/main/java/io/smallrye/graphql/execution/ExecutionResponse.java @@ -100,6 +100,9 @@ private JsonObjectBuilder addErrorsToResponse(JsonObjectBuilder returnObjectBuil } private JsonObjectBuilder addDataToResponse(JsonObjectBuilder returnObjectBuilder, ExecutionResult executionResult) { + if (!executionResult.isDataPresent()) { + return returnObjectBuilder; + } Object pojoData = executionResult.getData(); return addDataToResponse(returnObjectBuilder, pojoData); } diff --git a/server/integration-tests/src/test/java/io/smallrye/graphql/tests/customscalars/CustomScalarTest.java b/server/integration-tests/src/test/java/io/smallrye/graphql/tests/customscalars/CustomScalarTest.java index e9c988a12..cedbcb28e 100644 --- a/server/integration-tests/src/test/java/io/smallrye/graphql/tests/customscalars/CustomScalarTest.java +++ b/server/integration-tests/src/test/java/io/smallrye/graphql/tests/customscalars/CustomScalarTest.java @@ -84,12 +84,12 @@ public void inAsScalarRequiredTest() { assertThat(graphQLAssured .post("query { inAsScalarRequired(scalar: null) }")) .contains("NullValueForNonNullArgument@[inAsScalarRequired]") - .contains("\"data\":null"); + .doesNotContain("\"data\":"); assertThat(graphQLAssured .post("query { inAsScalarRequired }")) .contains("MissingFieldArgument@[inAsScalarRequired]") - .contains("\"data\":null"); + .doesNotContain("\"data\":"); } @Test @@ -131,7 +131,7 @@ public void inAsScalarListRequiredTest() { .post("query { inAsScalarListRequired(scalars: [null]) }")) .contains("WrongType@[inAsScalarListRequired]") .contains("must not be null") - .contains("\"data\":null"); + .doesNotContain("\"data\":"); } @Test diff --git a/server/integration-tests/src/test/java/io/smallrye/graphql/tests/error/UnparseableDocumentTestCase.java b/server/integration-tests/src/test/java/io/smallrye/graphql/tests/error/UnparseableDocumentTestCase.java index 4680d76b2..ec6730760 100644 --- a/server/integration-tests/src/test/java/io/smallrye/graphql/tests/error/UnparseableDocumentTestCase.java +++ b/server/integration-tests/src/test/java/io/smallrye/graphql/tests/error/UnparseableDocumentTestCase.java @@ -1,11 +1,13 @@ package io.smallrye.graphql.tests.error; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; + import java.net.URL; import org.eclipse.microprofile.graphql.GraphQLApi; import org.eclipse.microprofile.graphql.Query; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; @@ -47,7 +49,14 @@ public void tryUnparsableDocumentRequest() { String exceptionMessage = "Unparseable input document"; String response = graphQLAssured.post(request); - MatcherAssert.assertThat(response, Matchers.containsString(exceptionMessage)); + assertThat(response, containsString(exceptionMessage)); + // The response should not contain the "data" field. + // See: https://spec.graphql.org/draft/#sec-Response-Format + //// If the request included execution, the response map must contain an entry with key data. + //// The value of this entry is described in the "Data" section. + //// If the request failed before execution due to a syntax error, missing information, + //// or validation error, this entry must not be present. + assertThat(response, not(containsString("\"data\":"))); } } From 7a4d404a94beedfe22fe799f1549282555ba005f Mon Sep 17 00:00:00 2001 From: Marek Skacelik Date: Wed, 13 Nov 2024 11:09:37 +0100 Subject: [PATCH 2/2] Changed Quarkus testing source branch --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8cb06cca8..2b9781409 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -96,8 +96,8 @@ jobs: - name: checkout Quarkus repository uses: actions/checkout@v2 with: - repository: quarkusio/quarkus - ref: main + repository: mskacelik/quarkus + ref: srgql-2.11.1 path: quarkus - uses: actions/setup-java@v4