-
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.
Merge pull request #643 from phillip-kruger/1.0.x
Allowing `ToScalar` to pass in a method to use to deserialize.
- Loading branch information
Showing
30 changed files
with
540 additions
and
95 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
27 changes: 27 additions & 0 deletions
27
...on/schema-builder/src/test/java/io/smallrye/graphql/index/app/ClassWithOptionalField.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,27 @@ | ||
package io.smallrye.graphql.index.app; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
import java.util.OptionalDouble; | ||
|
||
import org.eclipse.microprofile.graphql.DateFormat; | ||
|
||
import io.smallrye.graphql.api.Scalar; | ||
import io.smallrye.graphql.api.ToScalar; | ||
|
||
public class ClassWithOptionalField { | ||
|
||
@ToScalar(Scalar.Int.class) | ||
public Optional<Long> id; | ||
|
||
public Optional<String> maybe; | ||
|
||
@DateFormat("dd MMM yyyy") | ||
public Optional<LocalDate> maybeOneDay; | ||
|
||
@ToScalar(Scalar.String.class) | ||
public Optional<Mapped> mapped; | ||
|
||
public OptionalDouble amount; | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
common/schema-builder/src/test/java/io/smallrye/graphql/index/app/CurrencyAdapter.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,27 @@ | ||
package io.smallrye.graphql.index.app; | ||
|
||
import java.util.Currency; | ||
|
||
import javax.json.Json; | ||
import javax.json.JsonObject; | ||
import javax.json.bind.adapter.JsonbAdapter; | ||
|
||
/** | ||
* Map a Currency to and from json | ||
* | ||
* @author Phillip Kruger ([email protected]) | ||
*/ | ||
public class CurrencyAdapter implements JsonbAdapter<Currency, JsonObject> { | ||
|
||
@Override | ||
public JsonObject adaptToJson(Currency currency) { | ||
return Json.createObjectBuilder() | ||
.add("currency", currency.getCurrencyCode()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public Currency adaptFromJson(JsonObject json) { | ||
return Currency.getInstance(json.getString("currencyCode")); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
common/schema-builder/src/test/java/io/smallrye/graphql/index/app/Mapped.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,25 @@ | ||
package io.smallrye.graphql.index.app; | ||
|
||
public class Mapped { | ||
private String value; | ||
|
||
public Mapped() { | ||
} | ||
|
||
public Mapped(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
common/schema-builder/src/test/java/io/smallrye/graphql/index/app/MappingResource.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,48 @@ | ||
package io.smallrye.graphql.index.app; | ||
|
||
import java.util.Currency; | ||
|
||
import javax.json.bind.annotation.JsonbTypeAdapter; | ||
|
||
import org.eclipse.microprofile.graphql.Description; | ||
import org.eclipse.microprofile.graphql.GraphQLApi; | ||
import org.eclipse.microprofile.graphql.Mutation; | ||
import org.eclipse.microprofile.graphql.Query; | ||
|
||
import io.smallrye.graphql.api.Scalar; | ||
import io.smallrye.graphql.api.ToScalar; | ||
|
||
@GraphQLApi | ||
public class MappingResource { | ||
|
||
@Mutation | ||
@Description("Add new Data") | ||
public Data createData(Data data) { | ||
data.id = (long) (Math.random() * 10000); | ||
return data; | ||
} | ||
|
||
@Query | ||
public Data getData() { | ||
Data d = new Data(); | ||
d.id = 1L; | ||
d.name = "Foo"; | ||
d.currency = Currency.getInstance("EUR"); | ||
return d; | ||
} | ||
|
||
public static class Data { | ||
public Long id; | ||
|
||
public String name; | ||
|
||
@ToScalar(Scalar.String.class) | ||
@JsonbTypeAdapter(CurrencyAdapter.class) | ||
public Currency currency; | ||
|
||
@ToScalar(Scalar.String.class) | ||
public Email email; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.