https://github.com/bharley/graphql-hashid-type
A scalar type for GraphQL that obscures your database identifiers using Hashids
https://github.com/bharley/graphql-hashid-type
graphql hashids javascript
Last synced: 5 months ago
JSON representation
A scalar type for GraphQL that obscures your database identifiers using Hashids
- Host: GitHub
- URL: https://github.com/bharley/graphql-hashid-type
- Owner: bharley
- Created: 2017-01-29T20:01:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-06T21:49:14.000Z (over 8 years ago)
- Last Synced: 2025-04-18T14:06:20.467Z (6 months ago)
- Topics: graphql, hashids, javascript
- Language: JavaScript
- Size: 5.86 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# graphql-hashid-type
A scalar type for [GraphQL] that obscures your database identifiers using
[Hashids].## Installation
Use yarn or npm:
```
$ yarn add graphql-hashid-type
``````
$ npm i -S graphql-hashid-type
```## Usage
```js
import {
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLString,
} from 'graphql';
import GraphQLHashIdType from 'graphql-hashid-type';const GraphQLHashId = new GraphQLHashIdType('super secret salt');
const FoodType = new GraphQLObjectType({
name: 'Food',
description: 'A possibly tasty thing',
fields: {
id: { type: new GraphQLNonNull(GraphQLHashId) },
name: { type: new GraphQLNonNull(GraphQLString) },
},
});const food = [
{ id: 1, name: 'Pizza' },
{ id: 2, name: 'Hamburger' },
{ id: 3, name: 'Burrito' },
];const RootType = new GraphQLObjectType({
name: 'RootType',
fields: {
food: {
type: new GraphQLList(FoodType),
resolve: () => food,
},
favorite: {
type: FoodType,
args: {
id: {
type: new GraphQLNonNull(GraphQLHashId)
}
},
resolve(root, { id }) {
return food.find(item => item.id === id);
},
}
}
});export default new GraphQLSchema({
query: RootType,
});
```[GraphQL]: http://graphql.org/
[Hashids]: http://hashids.org/