graphql-type-lowercase-string
v0.2.0
Published
Lowercase string scalar type for GraphQL.js
Downloads
5
Maintainers
Readme
graphql-type-lowercase-string
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