File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,16 +106,21 @@ public Object coerceLiteral(Object input) {
106106 });
107107
108108
109- // public static GraphQLScalarType GraphQLID = new GraphQLScalarType("ID", "Built-in ID", new Coercing() {
110- // @Override
111- // public Object coerce(Object input) {
112- // return input;
113- // }
114- //
115- // @Override
116- // public Object coerceLiteral(Object input) {
117- // return input;
118- // }
119- // });
109+ public static GraphQLScalarType GraphQLID = new GraphQLScalarType ("ID" , "Built-in ID" , new Coercing () {
110+ @ Override
111+ public Object coerce (Object input ) {
112+ if (input instanceof String ){
113+ return input ;
114+ }
115+
116+ throw new GraphQLException ();
117+ }
118+
119+ @ Override
120+ public Object coerceLiteral (Object input ) {
121+ if (!(input instanceof StringValue )) return null ;
122+ return ((StringValue ) input ).getValue ();
123+ }
124+ });
120125
121126}
Original file line number Diff line number Diff line change @@ -28,6 +28,24 @@ class ScalarsTest extends Specification {
2828 " test" | " test"
2929 }
3030
31+ def " ID coerce literal" () {
32+ expect :
33+ Scalars.GraphQLID . getCoercing(). coerceLiteral(literal) == result
34+
35+ where :
36+ literal | result
37+ new StringValue (" 5457486ABSBHS4w646" ) | " 5457486ABSBHS4w646"
38+ }
39+
40+ def " ID coerce object" () {
41+ expect :
42+ Scalars.GraphQLID . getCoercing(). coerce(value) == result
43+
44+ where :
45+ value | result
46+ " 5457486ABSBHS4w646" | " 5457486ABSBHS4w646"
47+ }
48+
3149 def " Int coerce literal" () {
3250 expect :
3351 Scalars.GraphQLInt . getCoercing(). coerceLiteral(literal) == result
You can’t perform that action at this time.
0 commit comments