-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fix for the incostistent error responses while using @nonnull a…
…nnotations
- Loading branch information
Showing
6 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ation-tests/src/test/java/io/smallrye/graphql/tests/nonnull/NonNullErrorResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.smallrye.graphql.tests.nonnull; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URL; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.smallrye.graphql.tests.GraphQLAssured; | ||
|
||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class NonNullErrorResponseTest { | ||
|
||
@Deployment | ||
public static WebArchive deployment() { | ||
return ShrinkWrap.create(WebArchive.class, "nonNull-test.war") | ||
.addClasses(SomeApi.class); | ||
} | ||
|
||
@ArquillianResource | ||
URL testingURL; | ||
|
||
@Test | ||
public void queryShouldNotReturnNonNullError() { | ||
GraphQLAssured graphQLAssured = new GraphQLAssured(testingURL); | ||
|
||
String response = graphQLAssured | ||
.post("{ echoNumber(number: \"something\") }"); | ||
assertThat(response).contains("Can not parse a number from [StringValue{value='something'}]"); | ||
assertThat(response).doesNotContain("NullValueInNonNullableField"); | ||
|
||
response = graphQLAssured | ||
.post("{ echoMessage(message: 314159) }"); | ||
|
||
assertThat(response) | ||
.contains("argument 'message' with value 'IntValue{value=314159}' is not a valid 'String'") | ||
.doesNotContain("NullValueInNonNullableField"); | ||
} | ||
|
||
@Test | ||
public void mutationShouldNotReturnNonNullError() { | ||
GraphQLAssured graphQLAssured = new GraphQLAssured(testingURL); | ||
|
||
String response = graphQLAssured | ||
.post("mutation { add(a: \"one\", b: \"two\") }"); | ||
assertThat(response).contains("Can not parse a number from [StringValue{value='one'}]") | ||
.contains("Can not parse a number from [StringValue{value='two'}]") | ||
.doesNotContain("NullValueInNonNullableField"); | ||
} | ||
|
||
@Test | ||
public void queryShouldReturnNonNullError() { | ||
GraphQLAssured graphQLAssured = new GraphQLAssured(testingURL); | ||
String response = graphQLAssured | ||
.post("{echoBigDecimal}"); | ||
assertThat(response).contains("NullValueInNonNullableField"); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
server/integration-tests/src/test/java/io/smallrye/graphql/tests/nonnull/SomeApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.smallrye.graphql.tests.nonnull; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import org.eclipse.microprofile.graphql.GraphQLApi; | ||
import org.eclipse.microprofile.graphql.Mutation; | ||
import org.eclipse.microprofile.graphql.NonNull; | ||
import org.eclipse.microprofile.graphql.Query; | ||
|
||
@GraphQLApi | ||
public class SomeApi { | ||
@Query | ||
public @NonNull Integer echoNumber(@NonNull Integer number) { | ||
return number; | ||
} | ||
|
||
@Query | ||
public @NonNull String echoMessage(@NonNull String message) { | ||
return message; | ||
} | ||
|
||
// in this case the '@NonNull' annotations are redundant | ||
@Mutation | ||
public @NonNull int add(@NonNull int a, @NonNull int b) { | ||
return a + b; | ||
} | ||
|
||
@Query | ||
public @NonNull BigDecimal echoBigDecimal() { | ||
return null; | ||
} | ||
} |