Skip to content

Commit 7c6d5ef

Browse files
fix: unknown scalar not handling variable values
1 parent 6da79ef commit 7c6d5ef

File tree

2 files changed

+23
-5
lines changed
  • hypertrace-core-graphql-common-schema/src

2 files changed

+23
-5
lines changed

hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/schema/typefunctions/UnknownScalar.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import graphql.language.StringValue;
1313
import graphql.schema.Coercing;
1414
import graphql.schema.CoercingParseLiteralException;
15-
import graphql.schema.CoercingParseValueException;
1615
import graphql.schema.CoercingSerializeException;
1716
import graphql.schema.GraphQLScalarType;
1817
import java.lang.reflect.AnnotatedType;
@@ -40,16 +39,17 @@ public Object serialize(Object fetcherResult) throws CoercingSerializeException
4039
}
4140

4241
@Override
43-
public Object parseValue(Object input) throws CoercingParseValueException {
44-
return this.parseFromAst(input, CoercingParseValueException::new);
42+
public Object parseValue(Object input) {
43+
return input;
4544
}
4645

4746
@Override
4847
public Object parseLiteral(Object input) throws CoercingParseLiteralException {
4948
return this.parseFromAst(input, CoercingParseLiteralException::new);
5049
}
5150

52-
private <E> Object parseFromAst(Object input, Function<Exception, E> errorWrapper) {
51+
private <E extends RuntimeException> Object parseFromAst(
52+
Object input, Function<Exception, E> errorWrapper) throws E {
5353
Function<Object, Object> recurse =
5454
value -> this.parseFromAst(value, errorWrapper);
5555

@@ -81,7 +81,7 @@ private <E> Object parseFromAst(Object input, Function<Exception, E> errorWrappe
8181
field -> recurse.apply(field.getValue())));
8282
}
8383

84-
return errorWrapper.apply(
84+
throw errorWrapper.apply(
8585
new IllegalArgumentException(
8686
String.format(
8787
"Unsupported input of type %s",

hypertrace-core-graphql-common-schema/src/test/java/org/hypertrace/core/graphql/common/schema/scalars/UnknownScalarTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
56
import static org.junit.jupiter.api.Assertions.assertTrue;
67

78
import graphql.annotations.processor.ProcessingElementsContainer;
@@ -10,6 +11,7 @@
1011
import graphql.language.FloatValue;
1112
import graphql.language.IntValue;
1213
import graphql.language.StringValue;
14+
import graphql.schema.CoercingParseLiteralException;
1315
import graphql.schema.GraphQLScalarType;
1416
import java.lang.reflect.AnnotatedType;
1517
import java.math.BigDecimal;
@@ -92,5 +94,21 @@ void canConvertFromLiteral() {
9294
ArrayValue.newArrayValue()
9395
.value(StringValue.newStringValue("five").build())
9496
.build()));
97+
98+
assertThrows(
99+
CoercingParseLiteralException.class,
100+
() -> unknownScalarType.getCoercing().parseLiteral("bad value"));
101+
}
102+
103+
@Test
104+
void canConvertFromValue() {
105+
// A dumb bug requires a dumb test
106+
assertEquals(true, unknownScalarType.getCoercing().parseValue(true));
107+
108+
assertEquals("value", unknownScalarType.getCoercing().parseValue("value"));
109+
110+
assertEquals(10, unknownScalarType.getCoercing().parseValue(10));
111+
112+
assertEquals(10.5, unknownScalarType.getCoercing().parseValue(10.5));
95113
}
96114
}

0 commit comments

Comments
 (0)