Code Monkey home page Code Monkey logo

graphql-type-uuid's Introduction

graphql-type-uuid npm

UUID scalar type for GraphQL.js.

Travis Codecov

Usage

This package exports a UUID scalar GraphQL.js type:

import GraphQLUUID from 'graphql-type-uuid';

This type can also be imported as follows using CommonJS:

const GraphQLUUID = require('graphql-type-uuid');

GraphQLUUID can represent any UUID version specified in RFC 4122.

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.

graphql-type-uuid's People

Contributors

dependabot[bot] avatar olistic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

graphql-type-uuid's Issues

UUID without -

What do you think if this library can support UUID formats without the - separator?

Reasoning: UUIDs are usually sent as strings but the underlying implementation is based on bits... making the - just a representation aid for the human eye.

Imports don't work in TypeScript

Need to do it the following way to make them work:

import * as GraphQLUUID from 'graphql-type-uuid';

I'm using NestJS's default TS config. Not really sure what the problem is. Just reporting, in case it can be fixed and in case someone else stumbles on this :)

Valid UUID does not match

I just found a valid UUID (02c44232-4ac6-6eda-9ad2-735096bbaf34) that does not pass the validation. Could you please have a look?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.