Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/olistic/graphql-type-uuid
UUID scalar type for GraphQL.js
https://github.com/olistic/graphql-type-uuid
graphql graphql-js uuid
Last synced: about 8 hours ago
JSON representation
UUID scalar type for GraphQL.js
- Host: GitHub
- URL: https://github.com/olistic/graphql-type-uuid
- Owner: olistic
- License: mit
- Created: 2018-07-12T15:11:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T01:45:48.000Z (almost 2 years ago)
- Last Synced: 2024-08-09T07:26:34.762Z (3 months ago)
- Topics: graphql, graphql-js, uuid
- Language: JavaScript
- Size: 1.37 MB
- Stars: 22
- Watchers: 1
- Forks: 3
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-type-uuid [![npm][npm-badge]][npm]
UUID scalar type for [GraphQL.js](https://github.com/graphql/graphql-js).
[![Travis][build-badge]][build] [![Codecov][codecov-badge]][codecov]
## Usage
This package exports a UUID scalar GraphQL.js type:
```js
import GraphQLUUID from 'graphql-type-uuid';
```This type can also be imported as follows using CommonJS:
```js
const GraphQLUUID = require('graphql-type-uuid');
```GraphQLUUID can represent any UUID version specified in
[RFC 4122](https://tools.ietf.org/html/rfc4122).### Programmatically-constructed schemas
You can use this in a programmatically-constructed schema as with any other
scalar type:```js
import { GraphQLObjectType } from 'graphql';
import GraphQLUUID from 'graphql-type-uuid';export default new GraphQLObjectType({
name: 'MyType',
fields: {
myField: { type: GraphQLUUID },
},
});
```### SDL with [graphql-tools](https://github.com/apollographql/graphql-tools)
When using the SDL with graphql-tools, define `GraphQLUUID` as the resolver for
the corresponding scalar type in your schema:```js
import { makeExecutableSchema } from 'graphql-tools';
import GraphQLUUID from 'graphql-type-uuid';const typeDefs = `
scalar UUIDtype 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](https://github.com/taion/graphql-type-json), in which this
project is heavily inspired.[npm-badge]: https://img.shields.io/npm/v/graphql-type-uuid.svg
[npm]: https://www.npmjs.com/package/graphql-type-uuid
[build-badge]:
https://img.shields.io/travis/olistic/graphql-type-uuid/master.svg
[build]: https://travis-ci.org/olistic/graphql-type-uuid
[codecov-badge]:
https://img.shields.io/codecov/c/github/olistic/graphql-type-uuid/master.svg
[codecov]: https://codecov.io/gh/olistic/graphql-type-uuid