graphql-type-lowercase-string

0.2.0 • Public • Published

Travis Codecov

graphql-type-lowercase-string npm

LowercaseString scalar type for GraphQL.js.

Usage

This package exports a LowercaseString scalar GraphQL.js type which is useful for ensuring a field has no uppercase characters e.g a username.

import GraphQLLowercaseString from 'graphql-type-lowercase-string';

Programmatically-constructed schemas

The type can be used in a programmatically constructed schema:

import { GraphQLObjectType } from 'graphql';
import GraphQLLowercaseString from 'graphql-type-lowercase-string';
 
export default new GraphQLObjectType({
  name: 'MyType',
  fields: {
    myField: { type: GraphQLLowercaseString },
  },
});

SDL with graphql-tools

When using the SDL with graphql-tools, define GraphQLLowercaseString as the resolver for the corresponding scalar type in the schema:

import { makeExecutableSchema } from 'graphql-tools';
import GraphQLLowercaseString from 'graphql-type-lowercase-string';
 
const typeDefs = `
scalar LowercaseString
 
type MyType {
  myField: LowercaseString
}
`;
 
const resolvers = {
  LowercaseString: GraphQLLowercaseString,
};
 
export default makeExecutableSchema({ typeDefs, resolvers });

Related

This project was inspired by graphql-type-json

Package Sidebar

Install

npm i graphql-type-lowercase-string

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

10.1 kB

Total Files

6

Last publish

Collaborators

  • cjjenkinson