https://github.com/mfix22/gnt
:cocktail: GraphQL Normalized Types
https://github.com/mfix22/gnt
credit-card drivers-license graphql graphql-types normalization normalize phonenumber scalars types us-state zipcode
Last synced: 4 months ago
JSON representation
:cocktail: GraphQL Normalized Types
- Host: GitHub
- URL: https://github.com/mfix22/gnt
- Owner: mfix22
- License: mit
- Created: 2017-05-07T19:51:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-04T22:14:12.000Z (almost 7 years ago)
- Last Synced: 2025-04-03T18:23:25.343Z (7 months ago)
- Topics: credit-card, drivers-license, graphql, graphql-types, normalization, normalize, phonenumber, scalars, types, us-state, zipcode
- Language: JavaScript
- Homepage: https://mfix22.github.io/gnt
- Size: 283 KB
- Stars: 32
- Watchers: 4
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# *G*raphQL *N*ormalized *T*ypes :cocktail:
The **g**in-**n**-**t**onic of GraphQL types: simple, final, clean. Normalize your common data with GraphQL Scalar types.[](https://github.com/facebook/jest)
[](https://lernajs.io/)
[](#contributing)
## Usage
```bash
$ npm install --save gnt
```and then add to your schema:
```javascript
const { Phone, UnixDate, CreditCard, State, ZipCode, DriversLicense } = require('gnt')
const { makeExecutableSchema } = require('graphql-tools');makeExecutableSchema({
typeDefs: schemaString,
resolvers: {
Phone,
UnixDate,
CreditCard,
USState: State,
ZipCode,
DriversLicense
}
});
```## Examples
Each of these types can be installed individually using there 'Package Name' shown below| Type | Package Name | Input Example | Output Example |
| :------------- | :------------- | :------------- | :------------- |
| Phone | `graphql-types-phone` | `'(817) 569-8900'` | `'+18175698900'` |
| Zipcode | `graphql-types-zipcode` | `'55902'`, `00000` | `'55902'`, `null` |
| UnixDate | `graphql-types-unix-timestamp` | `2017-05-07T14:47:59.438`, `Date` | `1494186489` |
| CreditCard | `graphql-types-credit-card` | `'4111111111111111'` | ```{ number: '4111111111111111', cardType: 'VISA', validCVV: false, validExpiryMonth: false, validExpiryYear: false, isExpired: true }``` |
| NonEmptyString | `graphql-types-non-empty-string` | `''` | `null` |
| Drivers License| `graphql-types-drivers-license` | `{ state: 'CA', license: 'B2347354' }`| `{ state: 'CA', license: 'B2347354' }` OR `null` |
#### Enum Types
| Type | Package Name | Input Example |
| :------------- | :------------- | :------------- |
| USState | `graphql-types-us-state` | `US`, `CA`, `DE` `...` |## Contributing
Contributions are more than welcome! This repo is not meant to be owned by me (and if there is a more suitable owner please [let me know](https://github.com/mfix22/gnt/issues)), but rather by the commuity.### Creating a new type
First run:
```shell
$ npm run generate -- ''
```
to get started. A folder with `index.js`, `index.spec.js` (your test), and a `package.json` will be created for you!
Then run `npm run link` and you should be on your way.If you have any idea for new types, please submit an issue or PR!