{"size": 820, "ext": "js", "max_stars_repo_path": "src/scalars/Email.js", "max_stars_repo_name": "tuev/express-starter-pet", "max_stars_repo_stars_event_min_datetime": "2019-06-08T16:37:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-08T16:37:10.000Z", "max_issues_repo_path": "src/scalars/Email.js", "max_issues_repo_name": "tuev/express-starter-pet", "max_issues_repo_issues_event_min_datetime": "2020-01-11T07:12:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-21T02:48:06.000Z", "max_forks_repo_path": "src/scalars/Email.js", "max_forks_repo_name": "tuev/graphql-express-starter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 160, "max_forks_count": null, "avg_line_length": 28.275862069, "max_line_length": 161, "alphanum_fraction": 0.5682926829}
import { GraphQLScalarType, GraphQLString } from 'graphql'
import { ApolloError } from 'apollo-server-express'
export const emailRegEx = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/

class EmailType extends GraphQLScalarType {
  constructor (type) {
    super({
      name: 'Email',
      parseValue: value => type.parseValue(value),
      serialize: value => type.serialize(value),
      parseLiteral: ast => {
        if (emailRegEx.test(ast.value)) {
          return type.parseLiteral(ast)
        }
        throw new ApolloError(
          'Email address failed validation',
          'INVALID_EMAIL'
        )
      }
    })
  }
}

export { EmailType }

export const emailScalar = {
  Email: new EmailType(GraphQLString)
}
