0.3.5 • Published 6 years ago

gnt v0.3.5

Weekly downloads
6
License
MIT
Repository
-
Last release
6 years ago

GraphQL Normalized Types :cocktail:

The gin-n-tonic of GraphQL types: simple, final, clean. Normalize your common data with GraphQL Scalar types.

tested with jest lerna contributions welcome

Usage

$ npm install --save gnt

and then add to your schema:

const { Phone, UnixDate, CreditCard, State, ZipCode, DriversLicense } = require('gnt')

{
  name: 'Query',
  fields: {
    phone: { type: Phone },
    date:  { type: UnixDate },
    card:  { type: CreditCard },
    state: { type: State }
    zipcode: { type: ZipCode },
    license: { type: DriversLicense }
  }  
}

Examples

Each of these types can be installed individually using there 'Package Name' shown below

TypePackage NameInput ExampleOutput Example
Phonegraphql-types-phone'(817) 569-8900''+18175698900'
Zipcodegraphql-types-zipcode'55902', 00000'55902', null
UnixDategraphql-types-unix-timestamp2017-05-07T14:47:59.438, Date1494186489
CreditCardgraphql-types-credit-card'4111111111111111'{ number: '4111111111111111', cardType: 'VISA', validCVV: false, validExpiryMonth: false, validExpiryYear: false, isExpired: true }
NonEmptyStringgraphql-types-non-empty-string''null
Drivers Licensegraphql-types-drivers-license{ state: 'CA', license: 'B2347354' }{ state: 'CA', license: 'B2347354' } OR null

Enum Types

TypePackage NameInput Example
USStategraphql-types-us-stateUS, 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), but rather by the commuity.

Creating a new type

First run:

$ npm run generate -- '<your type name>'

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!