Skip to content

Commit

Permalink
Fix spec reference in EmailAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Mar 27, 2023
1 parent ef0585a commit 7460ec4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-houses-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-scalars': patch
---

Fix the spec reference in \`EmailAddress\`
15 changes: 10 additions & 5 deletions src/scalars/EmailAddress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig, ASTNode } from 'graphql';
import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql';
import { createGraphQLError } from '../error.js';

const validate = (value: any, ast?: ASTNode) => {
Expand All @@ -16,21 +16,24 @@ const validate = (value: any, ast?: ASTNode) => {
return value;
};

const specifiedByURL = 'https://www.w3.org/Protocols/rfc822/';
const specifiedByURL = 'https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address';

export const GraphQLEmailAddressConfig = /*#__PURE__*/ {
name: 'EmailAddress',

description:
'A field whose value conforms to the standard internet email address format as specified in RFC822: https://www.w3.org/Protocols/rfc822/.',
'A field whose value conforms to the standard internet email address format as specified in HTML Spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address.',

serialize: validate,

parseValue: validate,

parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw createGraphQLError(`Can only validate strings as email addresses but got a: ${ast.kind}`, { nodes: ast });
throw createGraphQLError(
`Can only validate strings as email addresses but got a: ${ast.kind}`,
{ nodes: ast },
);
}

return validate(ast.value, ast);
Expand All @@ -47,4 +50,6 @@ export const GraphQLEmailAddressConfig = /*#__PURE__*/ {
},
} as GraphQLScalarTypeConfig<string, string>;

export const GraphQLEmailAddress: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLEmailAddressConfig);
export const GraphQLEmailAddress: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(
GraphQLEmailAddressConfig,
);

0 comments on commit 7460ec4

Please sign in to comment.