Skip to content

Commit 8e560f9

Browse files
committed
Updated example
1 parent 7a87a92 commit 8e560f9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

site/docs/APIReference-TypeSystem.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,27 @@ type GraphQLScalarTypeConfig<InternalType> = {
217217
```
218218
219219
The leaf values of any request and input values to arguments are
220-
Scalars (or Enums) and are defined with a name and a series of coercion
220+
Scalars (or Enums) and are defined with a name and a series of serialization
221221
functions used to ensure validity.
222222
223223
#### Example
224224
225225
```js
226226
var OddType = new GraphQLScalarType({
227227
name: 'Odd',
228-
coerce(value) {
229-
return value % 2 === 1 ? value : null;
228+
serialize: oddValue,
229+
parseValue: oddValue,
230+
parseLiteral(ast) {
231+
if (ast.kind === Kind.INT) {
232+
return oddValue(parseInt(ast.value, 10));
233+
}
234+
return null;
230235
}
231236
});
237+
238+
function oddValue(value) {
239+
return value % 2 === 1 ? value : null;
240+
}
232241
```
233242
234243
### GraphQLObjectType

0 commit comments

Comments
 (0)