Skip to content

Commit f0067be

Browse files
committed
change coerceLiteral to parseLiteral (inspired by the js impl)
1 parent 3a96047 commit f0067be

6 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/main/java/graphql/Scalars.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Object coerceValue(Object input) {
2929
}
3030

3131
@Override
32-
public Object coerceLiteral(Object input) {
32+
public Object parseLiteral(Object input) {
3333
if (!(input instanceof IntValue)) return null;
3434
return ((IntValue) input).getValue();
3535
}
@@ -56,7 +56,7 @@ public Object coerceValue(Object input) {
5656
}
5757

5858
@Override
59-
public Object coerceLiteral(Object input) {
59+
public Object parseLiteral(Object input) {
6060
if (!(input instanceof StringValue)) return null;
6161
return Long.parseLong(((StringValue) input).getValue());
6262
}
@@ -80,7 +80,7 @@ public Object coerceValue(Object input) {
8080
}
8181

8282
@Override
83-
public Object coerceLiteral(Object input) {
83+
public Object parseLiteral(Object input) {
8484
return ((FloatValue) input).getValue().floatValue();
8585
}
8686
});
@@ -97,7 +97,7 @@ public Object coerceValue(Object input) {
9797
}
9898

9999
@Override
100-
public Object coerceLiteral(Object input) {
100+
public Object parseLiteral(Object input) {
101101
if (!(input instanceof StringValue)) return null;
102102
return ((StringValue) input).getValue();
103103
}
@@ -124,7 +124,7 @@ public Object coerceValue(Object input) {
124124
}
125125

126126
@Override
127-
public Object coerceLiteral(Object input) {
127+
public Object parseLiteral(Object input) {
128128
if (!(input instanceof BooleanValue)) return null;
129129
return ((BooleanValue) input).isValue();
130130
}
@@ -147,7 +147,7 @@ public Object coerceValue(Object input) {
147147
}
148148

149149
@Override
150-
public Object coerceLiteral(Object input) {
150+
public Object parseLiteral(Object input) {
151151
if (!(input instanceof StringValue)) return null;
152152
return ((StringValue) input).getValue();
153153
}

src/main/java/graphql/execution/ValuesResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private Object coerceValueAst(GraphQLType type, Value inputValue, Map<String, Ob
113113
return variables.get(((VariableReference) inputValue).getName());
114114
}
115115
if (type instanceof GraphQLScalarType) {
116-
return ((GraphQLScalarType) type).getCoercing().coerceLiteral(inputValue);
116+
return ((GraphQLScalarType) type).getCoercing().parseLiteral(inputValue);
117117
}
118118
if (type instanceof GraphQLNonNull) {
119119
return coerceValueAst(((GraphQLNonNull) type).getWrappedType(), inputValue, variables);
@@ -122,7 +122,7 @@ private Object coerceValueAst(GraphQLType type, Value inputValue, Map<String, Ob
122122
return coerceValueAstForInputObject((GraphQLInputObjectType) type, (ObjectValue) inputValue, variables);
123123
}
124124
if (type instanceof GraphQLEnumType) {
125-
return ((GraphQLEnumType) type).getCoercing().coerceLiteral(inputValue);
125+
return ((GraphQLEnumType) type).getCoercing().parseLiteral(inputValue);
126126
}
127127
if (type instanceof GraphQLList) {
128128
return coerceValueAstForList((GraphQLList) type, inputValue, variables);

src/main/java/graphql/schema/Coercing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public interface Coercing {
1212
* @param input
1313
* @return return null if not valid
1414
*/
15-
Object coerceLiteral(Object input);
15+
Object parseLiteral(Object input);
1616
}

src/main/java/graphql/schema/GraphQLEnumType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Object coerceValue(Object input) {
2929
}
3030

3131
@Override
32-
public Object coerceLiteral(Object input) {
32+
public Object parseLiteral(Object input) {
3333
if (!(input instanceof EnumValue)) return null;
3434
EnumValue enumValue = (EnumValue) input;
3535
GraphQLEnumValueDefinition enumValueDefinition = valueDefinitionMap.get(enumValue.getName());

src/main/java/graphql/validation/ValidationUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public boolean isValidLiteralValue(Value value, GraphQLType type) {
3333
}
3434

3535
if (type instanceof GraphQLScalarType) {
36-
return ((GraphQLScalarType) type).getCoercing().coerceLiteral(value) != null;
36+
return ((GraphQLScalarType) type).getCoercing().parseLiteral(value) != null;
3737
}
3838
if (type instanceof GraphQLEnumType) {
39-
return ((GraphQLEnumType) type).getCoercing().coerceLiteral(value) != null;
39+
return ((GraphQLEnumType) type).getCoercing().parseLiteral(value) != null;
4040
}
4141

4242
if (type instanceof GraphQLList) {

src/test/groovy/graphql/ScalarsTest.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ScalarsTest extends Specification {
1111

1212
def "String coerce literal"() {
1313
expect:
14-
Scalars.GraphQLString.getCoercing().coerceLiteral(literal) == result
14+
Scalars.GraphQLString.getCoercing().parseLiteral(literal) == result
1515

1616
where:
1717
literal | result
@@ -30,7 +30,7 @@ class ScalarsTest extends Specification {
3030

3131
def "ID coerce literal"() {
3232
expect:
33-
Scalars.GraphQLID.getCoercing().coerceLiteral(literal) == result
33+
Scalars.GraphQLID.getCoercing().parseLiteral(literal) == result
3434

3535
where:
3636
literal | result
@@ -48,7 +48,7 @@ class ScalarsTest extends Specification {
4848

4949
def "Int coerce literal"() {
5050
expect:
51-
Scalars.GraphQLInt.getCoercing().coerceLiteral(literal) == result
51+
Scalars.GraphQLInt.getCoercing().parseLiteral(literal) == result
5252

5353
where:
5454
literal | result
@@ -68,7 +68,7 @@ class ScalarsTest extends Specification {
6868

6969
def "Long coerce literal"() {
7070
expect:
71-
Scalars.GraphQLLong.getCoercing().coerceLiteral(literal) == result
71+
Scalars.GraphQLLong.getCoercing().parseLiteral(literal) == result
7272

7373
where:
7474
literal | result
@@ -87,7 +87,7 @@ class ScalarsTest extends Specification {
8787

8888
def "Float coerce literal"() {
8989
expect:
90-
Scalars.GraphQLFloat.getCoercing().coerceLiteral(literal) == result
90+
Scalars.GraphQLFloat.getCoercing().parseLiteral(literal) == result
9191

9292
where:
9393
literal | result
@@ -107,7 +107,7 @@ class ScalarsTest extends Specification {
107107

108108
def "Boolean coerce literal"() {
109109
expect:
110-
Scalars.GraphQLBoolean.getCoercing().coerceLiteral(literal) == result
110+
Scalars.GraphQLBoolean.getCoercing().parseLiteral(literal) == result
111111

112112
where:
113113
literal | result

0 commit comments

Comments
 (0)