File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff 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 * ```
You can’t perform that action at this time.
0 commit comments