File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 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.
214214``` js
215215const OddType = new GraphQLScalarType ({
216216 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+ },
219228 parseLiteral(ast) {
229+ // This function gets called when the value is passed in as a literal on the
230+ // Executable GraphQL Document
220231 if (ast.kind === Kind.INT) {
221232 return oddValue(parseInt(ast.value, 10));
222233 }
You can’t perform that action at this time.
0 commit comments