Skip to content

Commit 05e0d19

Browse files
jfairleyjmcdo29
andauthored
docs: refactor sample scalar code
Co-authored-by: Jay McDoniel <[email protected]>
1 parent f2d38d9 commit 05e0d19

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

content/graphql/scalars.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ To define a custom scalar, create a new `GraphQLScalarType` instance. We'll crea
121121
const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
122122

123123
function validate(uuid: unknown): string | never {
124-
if (typeof uuid !== "string") throw new Error("invalid uuid");
125-
if (!regex.test(uuid)) throw new Error("invalid uuid");
124+
if (typeof uuid !== "string" || !regex.test(uuid)) {
125+
throw new Error("invalid uuid");
126+
}
126127
return uuid;
127128
}
128129

0 commit comments

Comments
 (0)