graphql-type-email

0.1.0 • Public • Published

Travis Codecov

graphql-type-email npm

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

Package Sidebar

Install

npm i graphql-type-email

Weekly Downloads

58

Version

0.1.0

License

MIT

Unpacked Size

9.94 kB

Total Files

6

Last publish

Collaborators

  • cjjenkinson