File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -214,9 +214,20 @@ functions used to ensure validity.
214
214
``` js
215
215
const OddType = new GraphQLScalarType ({
216
216
name: ' Odd' ,
217
- serialize: oddValue,
218
- parseValue: oddValue,
217
+ description:
218
+ ' This custom scalar will only return a value if the passed in value is an odd integer, when it' s not it will return null .'
219
+ serialize: (outputValue) => {
220
+ // This function gets called for response-data, the application returns data
221
+ // for a property and in the schema we see that this value has the "Odd" type.
222
+ return typeof outputValue === ' number' && outputValue % 2 === 1 ? value : null;
223
+ },
224
+ parseValue: (inputValue) => {
225
+ // This function gets called for input-data, i.e. variables being passed in
226
+ return typeof inputValue === ' number' && outputValue % 2 === 1 ? value : null;
227
+ },
219
228
parseLiteral(ast) {
229
+ // This function gets called when the value is passed in as a literal on the
230
+ // Executable GraphQL Document
220
231
if (ast.kind === Kind.INT) {
221
232
return oddValue(parseInt(ast.value, 10));
222
233
}
You can’t perform that action at this time.
0 commit comments