File tree 1 file changed +12
-6
lines changed
1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -562,20 +562,26 @@ export interface GraphQLScalarTypeExtensions {
562
562
* Scalars (or Enums) and are defined with a name and a series of functions
563
563
* used to parse input from ast or variables and to ensure validity.
564
564
*
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
569
568
*
570
569
* Example:
571
570
*
572
571
* ```ts
573
572
* const OddType = new GraphQLScalarType({
574
573
* name: 'Odd',
575
574
* 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
+ * );
578
579
* }
580
+ *
581
+ * if (value % 2 === 0) {
582
+ * throw new Error(`Scalar "Odd" cannot represent "${value}" since it is even.`);
583
+ * }
584
+ * return value;
579
585
* }
580
586
* });
581
587
* ```
You can’t perform that action at this time.
0 commit comments