cjjenkinson / graphql-type-email

RFC822 spec compliant email address scalar type for GraphQL.js

Home Page:https://www.npmjs.com/package/graphql-type-email

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

RFC822 spec compliant email address scalar type for GraphQL.js

https://www.npmjs.com/package/graphql-type-email

License:MIT License


Languages

Language:JavaScript 100.0%