graphql-type-uuid

UUID scalar type for GraphQL.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
graphql-type-uuid
0.2.06 years ago6 years agoMinified + gzip package size for graphql-type-uuid in KB

Readme

graphql-type-uuid !npmnpm-badgenpm
UUID scalar type for GraphQL.js.
!Travisbuild-badgebuild !Codecovcodecov-badgecodecov

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.