graphql-type-email

RFC822 spec compliant email address scalar type for GraphQL.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
graphql-type-email
530.1.04 years ago4 years agoMinified + gzip package size for graphql-type-email in KB

Readme

!Travisbuild-badgebuild !Codecovcodecov-badgecodecov
graphql-type-email !npmnpm-badgenpm
RFC822 spec compliant email address scalar type for GraphQL.js.

Usage

This package exports a Email scalar GraphQL.js type which is useful for ensuring a field is a valid internet email address.
import GraphQLEmail from 'graphql-type-email';

Programmatically-constructed schemas

The type can be used in a programmatically constructed schema:
import { GraphQLObjectType } from 'graphql';
import GraphQLEmail from 'graphql-type-email';

export default new GraphQLObjectType({
  name: 'MyType',
  fields: {
    myField: { type: GraphQLEmail },
  },
});

SDL with graphql-tools

When using the SDL with graphql-tools, define GraphQLEmail as the resolver for the corresponding scalar type in the schema:
import { makeExecutableSchema } from 'graphql-tools';
import GraphQLEmail from 'graphql-type-email';

const typeDefs = `
scalar Email

type MyType {
  myField: Email
}
`;

const resolvers = {
  Email: GraphQLLEmail,
};

export default makeExecutableSchema({ typeDefs, resolvers });

Related

This project was inspired by graphql-type-json & graphql-type-uuid