-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2253
- Loading branch information
Showing
3 changed files
with
99 additions
and
4 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
42 changes: 42 additions & 0 deletions
42
client/tck/src/main/java/tck/graphql/typesafe/NillableBehavior.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,42 @@ | ||
package tck.graphql.typesafe; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
import org.eclipse.microprofile.graphql.Mutation; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.smallrye.graphql.client.typesafe.api.GraphQLClientApi; | ||
|
||
class NillableBehavior { | ||
private final TypesafeGraphQLClientFixture fixture = TypesafeGraphQLClientFixture.load(); | ||
|
||
@GraphQLClientApi | ||
interface StringMutationApi { | ||
@Mutation | ||
String createSome(SomeInput s); | ||
} | ||
|
||
@Test | ||
void nillableFieldsAreSet() { | ||
fixture.returnsData("'createSome':'foo'"); | ||
StringMutationApi api = fixture.build(StringMutationApi.class); | ||
|
||
String response = api.createSome(new SomeInput("all", "a", "b", "c")); | ||
|
||
then(fixture.query()).isEqualTo("mutation createSome($s: SomeInput) { createSome(s: $s) }"); | ||
then(fixture.variables()).isEqualTo("{'s':{'name':'all','first':'a','second':'b','third':'c'}}"); | ||
then(response).isEqualTo("foo"); | ||
} | ||
|
||
@Test | ||
void nillableFieldsAreNull() { | ||
fixture.returnsData("'createSome':'bar'"); | ||
StringMutationApi api = fixture.build(StringMutationApi.class); | ||
|
||
String response = api.createSome(new SomeInput("none")); | ||
|
||
then(fixture.query()).isEqualTo("mutation createSome($s: SomeInput) { createSome(s: $s) }"); | ||
then(fixture.variables()).isEqualTo("{'s':{'name':'none','second':null,'third':null}}"); | ||
then(response).isEqualTo("bar"); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
client/tck/src/main/java/tck/graphql/typesafe/SomeInput.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,47 @@ | ||
package tck.graphql.typesafe; | ||
|
||
import java.util.Objects; | ||
|
||
import jakarta.json.bind.annotation.JsonbNillable; | ||
import jakarta.json.bind.annotation.JsonbProperty; | ||
|
||
import org.eclipse.microprofile.graphql.Input; | ||
|
||
@Input("SomeInput") | ||
public class SomeInput { | ||
private String name; | ||
|
||
@JsonbProperty("first") | ||
private String firstAtrribute; | ||
|
||
@JsonbProperty(value = "second", nillable = true) | ||
private String secondAtrribute; | ||
|
||
@JsonbNillable | ||
private String third; | ||
|
||
public SomeInput() { | ||
} | ||
|
||
public SomeInput(String name) { | ||
this.name = name; | ||
} | ||
|
||
public SomeInput(String name, String first, String second, String third) { | ||
this.name = name; | ||
this.firstAtrribute = first; | ||
this.secondAtrribute = second; | ||
this.third = third; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, firstAtrribute, secondAtrribute, third); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SomeInput [name=" + name + ", firstAtrribute=" + firstAtrribute + ", secondAtrribute=" + secondAtrribute | ||
+ ", third=" + third + "]"; | ||
} | ||
} |