graphql-type-uuid
v0.2.0
Published
UUID scalar type for GraphQL.js
Downloads
16,821
Readme
graphql-type-uuid
UUID scalar type for GraphQL.js.
Usage
This package exports a UUID scalar GraphQL.js type:
import GraphQLUUID from 'graphql-type-uuid';
Programmatically-constructed schemas
You can use this in a programmatically-constructed schema as with any other scalar type:
import { GraphQLObjectType } from 'graphql';
import GraphQLUUID from 'graphql-type-uuid';
export default new GraphQLObjectType({
name: 'MyType',
fields: {
myField: { type: GraphQLUUID },
},
});
SDL with graphql-tools
When using the SDL with graphql-tools, define GraphQLUUID
as the resolver for
the corresponding scalar type in your schema:
import { makeExecutableSchema } from 'graphql-tools';
import GraphQLUUID from 'graphql-type-uuid';
const typeDefs = `
scalar UUID
type MyType {
myField: UUID
}
`;
const resolvers = {
UUID: GraphQLUUID,
};
export default makeExecutableSchema({ typeDefs, resolvers });
Related
If you happen to be looking for a JSON scalar GraphQL.js type, please check graphql-type-json, in which this project is heavily inspired.