Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed unnecessary "data": null if request failed before execution #2225

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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\":")));
}

}
Loading