Skip to content

Commit da57238

Browse files
GinhingIvanGoncharov
andauthoredFeb 21, 2022
correct outdated documentation (#3505)
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
1 parent 6407307 commit da57238

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
 

‎src/type/definition.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -562,20 +562,26 @@ export interface GraphQLScalarTypeExtensions {
562562
* Scalars (or Enums) and are defined with a name and a series of functions
563563
* used to parse input from ast or variables and to ensure validity.
564564
*
565-
* If a type's serialize function does not return a value (i.e. it returns
566-
* `undefined`) then an error will be raised and a `null` value will be returned
567-
* in the response. If the serialize function returns `null`, then no error will
568-
* be included in the response.
565+
* If a type's serialize function returns `null` or does not return a value
566+
* (i.e. it returns `undefined`) then an error will be raised and a `null`
567+
* value will be returned in the response. It is always better to validate
569568
*
570569
* Example:
571570
*
572571
* ```ts
573572
* const OddType = new GraphQLScalarType({
574573
* name: 'Odd',
575574
* serialize(value) {
576-
* if (value % 2 === 1) {
577-
* return value;
575+
* if (!Number.isFinite(value)) {
576+
* throw new Error(
577+
* `Scalar "Odd" cannot represent "${value}" since it is not a finite number.`,
578+
* );
578579
* }
580+
*
581+
* if (value % 2 === 0) {
582+
* throw new Error(`Scalar "Odd" cannot represent "${value}" since it is even.`);
583+
* }
584+
* return value;
579585
* }
580586
* });
581587
* ```

0 commit comments

Comments
 (0)
Please sign in to comment.