|
5 | 5 | import graphql.ExecutionResultImpl; |
6 | 6 | import graphql.GraphQLException; |
7 | 7 | import graphql.PublicSpi; |
| 8 | +import graphql.SerializationError; |
8 | 9 | import graphql.TypeResolutionEnvironment; |
9 | 10 | import graphql.execution.instrumentation.Instrumentation; |
10 | 11 | import graphql.execution.instrumentation.InstrumentationContext; |
11 | 12 | import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters; |
12 | 13 | import graphql.execution.instrumentation.parameters.InstrumentationFieldParameters; |
13 | 14 | import graphql.language.Field; |
| 15 | +import graphql.schema.CoercingSerializeException; |
14 | 16 | import graphql.schema.DataFetcher; |
15 | 17 | import graphql.schema.DataFetchingEnvironment; |
16 | 18 | import graphql.schema.DataFetchingEnvironmentImpl; |
@@ -141,7 +143,7 @@ protected ExecutionResult completeValue(ExecutionContext executionContext, Execu |
141 | 143 | } else if (fieldType instanceof GraphQLList) { |
142 | 144 | return completeValueForList(executionContext, parameters, fields, toIterable(result)); |
143 | 145 | } else if (fieldType instanceof GraphQLScalarType) { |
144 | | - return completeValueForScalar((GraphQLScalarType) fieldType, parameters, result); |
| 146 | + return completeValueForScalar((GraphQLScalarType) fieldType, parameters, result, executionContext); |
145 | 147 | } else if (fieldType instanceof GraphQLEnumType) { |
146 | 148 | return completeValueForEnum((GraphQLEnumType) fieldType, parameters, result); |
147 | 149 | } |
@@ -225,8 +227,16 @@ protected ExecutionResult completeValueForEnum(GraphQLEnumType enumType, Executi |
225 | 227 | return new ExecutionResultImpl(serialized, null); |
226 | 228 | } |
227 | 229 |
|
228 | | - protected ExecutionResult completeValueForScalar(GraphQLScalarType scalarType, ExecutionStrategyParameters parameters, Object result) { |
229 | | - Object serialized = scalarType.getCoercing().serialize(result); |
| 230 | + protected ExecutionResult completeValueForScalar(GraphQLScalarType scalarType, ExecutionStrategyParameters parameters, Object result, ExecutionContext context) { |
| 231 | + Object serialized; |
| 232 | + try { |
| 233 | + serialized = scalarType.getCoercing().serialize(result); |
| 234 | + } catch (CoercingSerializeException e) { |
| 235 | + serialized = null; |
| 236 | + context.addError(new SerializationError(e)); |
| 237 | + } |
| 238 | + |
| 239 | + // TODO: fix that: this should not be handled here |
230 | 240 | //6.6.1 http://facebook.github.io/graphql/#sec-Field-entries |
231 | 241 | if (serialized instanceof Double && ((Double) serialized).isNaN()) { |
232 | 242 | serialized = null; |
|
0 commit comments