graphql-type-email
v0.1.0
Published
RFC822 spec compliant email address scalar type for GraphQL.js
Downloads
225
Maintainers
Readme
graphql-type-email
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