{"_id":"@ardatan/graphql-scalars","_rev":"1-241952da1b925e051738718d881a6646","name":"@ardatan/graphql-scalars","dist-tags":{"alpha":"0.4.6-623be8c.2","latest":"0.4.6-623be8c.2"},"versions":{"0.4.6-623be8c.2":{"name":"@ardatan/graphql-scalars","version":"0.4.6-623be8c.2","description":"A collection of scalar types not included in base GraphQL.","repository":{"type":"git","url":"git+https://github.com/Urigo/graphql-scalars.git"},"sideEffects":false,"main":"dist/commonjs/index.js","module":"dist/esnext/index.js","typings":"dist/esnext/index.d.ts","typescript":{"definition":"dist/esnext/index.d.ts"},"license":"MIT","jest":{"roots":["src"]},"prettier":{"singleQuote":true,"trailingComma":"all","printWidth":80},"scripts":{"clean":"rm -rf dist","prebuild":"yarn clean","build":"tsc -m esnext --outDir dist/esnext && tsc -m commonjs --outDir dist/commonjs","test":"jest","prepare-release":"yarn build && yarn test","release":"yarn prepare-release && npm publish","ci:release:canary":"node bump.js && npm publish --tag alpha --access public"},"devDependencies":{"@types/glob":"7.1.1","@types/graphql":"14.2.1","@types/jest":"24.0.15","@graphql-modules/core":"0.7.5","graphql":"14.1.1","jest":"24.0.0","lint-staged":"8.2.1","semver":"6.1.2","ts-jest":"24.0.2","tslint":"5.18.0","typescript":"3.5.2"},"optionalDependencies":{"@graphql-modules/core":"0.7.5"},"peerDependencies":{"graphql":"^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"},"lint-staged":{"*.{ts,tsx}":["tslint --fix","git add"],"*.{js,json,css,md,ts,tsx}":["prettier --write","git add -f"]},"dependencies":{"graphql-bigint":"1.0.0","@graphql-modules/core":"0.7.5"},"gitHead":"623be8ceba0120daf4a01ffdfe4034ff0f0807df","bugs":{"url":"https://github.com/Urigo/graphql-scalars/issues"},"homepage":"https://github.com/Urigo/graphql-scalars#readme","_id":"@ardatan/graphql-scalars@0.4.6-623be8c.2","_nodeVersion":"10.15.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-8XUutqrUQ9kaF8NO+iK/lyVTJQH4es1tXqVxAle73KMh14kjw9wfs01Wlp0aq39eLuf3Hgyc5GES3qnMgFrXtw==","shasum":"c60fedc3f588e43f4d79ff96005fe8eb633a4cc1","tarball":"https://registry.npmjs.org/@ardatan/graphql-scalars/-/graphql-scalars-0.4.6-623be8c.2.tgz","fileCount":160,"unpackedSize":256798,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdE6wuCRA9TVsSAnZWagAAmw8P/RBuyXM++mJHdwRHjDTq\nn5EsrIHD3N3PrhE9Iobh4NVehRqLLHkrDGpa2F6xg92w5MZGW57aOADKPkUc\nXptN/FIqgjnBrAHHGacEbcs391pGc7idsBtQSNPpW+x6apYtt6XRIHEiC6i2\n3nTmNPL8dUpaDIuT9L6/DdqWSTeU0sQXsPpyTAd7yUnoxTfyfo/uO9NihzEu\nyMmx6OgEvxCJ2ZdAjpbpwwxhnv0yBP4d7V8L8iLbjSJCJe+S3BhZikmagXkh\nNjlkLwV0dFjY1IxYIXcgZlNSGCIh7FcZpzBBD5afXfcnkODjDzRyuaLB/SFg\nZkLT502Qibn/fPxfOnWcnCMMPwSMm1sgtVoYBGV/06gZFl+xCwEo+uEuw20e\n+8YBbiV5DYjRr2VeEeZ9sybQRiuJUF4QPMINzLj/M+pV0OwCqTfn1cdOWtnB\nghJ5a22Wn4jSjPV0+UhdEnDQ2Drhz2AT7ub3cROpvLeSOgXFioTr5If/H9il\nXwigOGYfIKHm/aoeOllzbiRzHntiKIh37rrxoB40tiNzvBG5JlrwOzYKtlC/\nihnOT54s6qX2iA/OAhXO4PFL53XBzoXnUrAjAD3gnAuxa3L3M7YBLCM8Bbh+\niYYhWyP2Ik5Kg8jy2/JI+ic3m5FuevLqfkCTZv7ltpa3NOuehiNSX9QQy40F\n6pJk\r\n=5Qav\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIALrsDOpj1XMN5WrKCXkHvElDxn3j/adQyY/zSVvkor4AiEAoKzbnCotQVSjYcSMWINNkmDFP0Er9rlDjdcXT88WKBE="}]},"maintainers":[{"name":"ardatan","email":"ardatanrikulu@gmail.com"}],"_npmUser":{"name":"ardatan","email":"ardatanrikulu@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-scalars_0.4.6-623be8c.2_1561570349562_0.5588652500638853"},"_hasShrinkwrap":false}},"time":{"created":"2019-06-26T17:32:29.528Z","0.4.6-623be8c.2":"2019-06-26T17:32:29.708Z","modified":"2022-04-04T15:22:25.195Z"},"maintainers":[{"name":"ardatan","email":"ardatanrikulu@gmail.com"}],"description":"A collection of scalar types not included in base GraphQL.","homepage":"https://github.com/Urigo/graphql-scalars#readme","repository":{"type":"git","url":"git+https://github.com/Urigo/graphql-scalars.git"},"bugs":{"url":"https://github.com/Urigo/graphql-scalars/issues"},"license":"MIT","readme":"# @okgrow/graphql-scalars\n\n[![npm version](https://badge.fury.io/js/%40okgrow%2Fgraphql-scalars.svg)](https://badge.fury.io/js/%40okgrow%2Fgraphql-scalars)\n[![CircleCI](https://circleci.com/gh/Urigo/graphql-scalars.svg?style=svg)](https://circleci.com/gh/Urigo/graphql-scalars)\n\n> A library of custom GraphQL [scalar types](http://graphql.org/learn/schema/#scalar-types) for creating precise type-safe GraphQL schemas.\n\n## Installation\n\n```\nnpm install --save @okgrow/graphql-scalars\n```\n\nor\n\n```\nyarn add @okgrow/graphql-scalars\n```\n\n## Usage\n\nTo use these scalars you'll need to add them in two places, your schema and your resolvers map.\n\nNOTE: The new `RegularExpression` scalar will be used a little differently and is explained below.\n\nIn your schema:\n\n```graphql\nscalar DateTime\n\nscalar EmailAddress\n\nscalar NegativeFloat\n\nscalar NegativeInt\n\nscalar NonNegativeFloat\n\nscalar NonNegativeInt\n\nscalar NonPositiveFloat\n\nscalar NonPositiveInt\n\nscalar PhoneNumber\n\nscalar PositiveFloat\n\nscalar PositiveInt\n\nscalar PostalCode\n\nscalar RegularExpression\n\nscalar UnsignedFloat\n\nscalar UnsignedInt\n\nscalar URL\n```\n\nIn your resolver map, first import them:\n\n```javascript\nimport {\n  DateTime,\n  NonPositiveInt,\n  PositiveInt,\n  NonNegativeInt,\n  NegativeInt,\n  NonPositiveFloat,\n  PositiveFloat,\n  NonNegativeFloat,\n  NegativeFloat,\n  EmailAddress,\n  URL,\n  PhoneNumber,\n  PostalCode,\n} from '@okgrow/graphql-scalars';\n```\n\nThen make sure they're in the root resolver map like this:\n\n```javascript\nconst myResolverMap = {\n  DateTime,\n\n  NonPositiveInt,\n  PositiveInt,\n  NonNegativeInt,\n  NegativeInt,\n\n  NonPositiveFloat,\n  PositiveFloat,\n  NonNegativeFloat,\n  NegativeFloat,\n\n  EmailAddress,\n  URL,\n\n  PhoneNumber,\n  PostalCode,\n\n  Query: {\n    // more stuff here\n  },\n\n  Mutation: {\n    // more stuff here\n  },\n};\n```\n\nNOTE: `NonNegativeFloat` and `NonNegativeInt` are also available under the aliases `UnsignedFloat`\nand `UnsignedInt`, respectively.\n\nAlternatively, use the default import and ES6's spread operator syntax:\n\n```javascript\nimport OKGGraphQLScalars from '@okgrow/graphql-scalars';\n```\n\nThen make sure they're in the root resolver map like this:\n\n```javascript\nconst myResolverMap = {\n  ...OKGGraphQLScalars,\n\n  Query: {\n    // more stuff here\n  },\n\n  Mutation: {\n    // more stuff here\n  },\n};\n```\n\nThat's it. Now you can use these scalar types in your schema definition like this:\n\n```graphql\ntype Person {\n  birthDate: DateTime\n  ageInYears: PositiveInt\n\n  heightInInches: PositiveFloat\n\n  minimumHourlyRate: NonNegativeFloat\n\n  currentlyActiveProjects: NonNegativeInt\n\n  email: EmailAddress\n  homePage: URL\n\n  phoneNumber: PhoneNumber\n  homePostalCode: PostalCode\n}\n```\n\nThese scalars can be used just like the base, built-in ones.\n\n### Usage with Apollo Server\n\n```javascript\nimport { ApolloServer } from 'apollo-server';\nimport { makeExecutableSchema } from 'graphql-tools';\n// import all scalars and resolvers\nimport OKGGraphQLScalars, {\n  OKGScalarDefinitions,\n} from '@okgrow/graphql-scalars';\n// Alternatively, import individual scalars and resolvers\n// import { DateTime, DateTimeScalar, ... } from \"@okgrow/graphql-scalars\"\n\nconst server = new ApolloServer({\n  schema: makeExecutableSchema({\n    typeDefs: [\n      // use spread syntax to add scalar definitions to your schema\n      ...OKGScalarDefinitions,\n      // DateTimeScalar,\n      // ...\n      // ... other type definitions ...\n    ],\n    resolvers: {\n      // use spread syntax to add scalar resolvers to your resolver map\n      ...OKGGraphQLScalars,\n      // DateTime,\n      // ...\n      // ... remainder of resolver map ...\n    },\n  }),\n});\n\nserver.listen().then(({ url }) => {\n  console.log(`🚀 Server ready at ${url}`);\n});\n```\n\n### Using the RegularExpression scalar\n\nFirst an explanation: To create a new scalar type to the GraphQL schema language, you must create an\ninstance of a new `GraphQLScalarType` object that implements three general functions/methods:\n`serialize`, `parseValue` and `parseLiteral` which are used at different stages of processing your\nGraphQL types during queries and mutations. So creating a new scalar looks like this:\n\n```javascript\nconst MyScalar = new GraphQLScalarType({\n    'MyScalar',\n\n    description: 'A description of my scalar',\n\n    serialize(value) {\n      // ...\n      return value;\n    },\n\n    parseValue(value) {\n      // ...\n      return value;\n    },\n\n    parseLiteral(ast) {\n      // ...\n      return ast.value;\n    }\n  });\n```\n\nGiven this, if we want to create a new type that is essentially the same except for one little\ncustomizable aspect (e.g., a regular expression type that has all the same code except the regex is\ndifferent) then we need to dynamically _generate_ a new `GraphQLScalarType` object given some\nparameters. That's the approach we take here.\n\nTherefore the `RegularExpression` scalar type is really a `GraphQLScalarType` object _generator_\nthat takes two arguments:\n\n- a name\n- the regex you want it to use\n\nSo to create a new scalar for a given regex, you will do this:\n\n```javascript\nconst MyRegexType = new RegularExpression('MyRegexType', /^ABC$/);\n```\n\nNow `MyRegexType` is your new GraphQL scalar type that will enforce a value of, in this case, \"ABC\".\n\nAdd your new scalar type to your resolver map:\n\n```javascript\nexport default {\n  MyRegexType,\n};\n```\n\nAnd to your schema:\n\n```graphql\nscalar MyRegexType\n```\n\nThat's it. Now you can use `MyRegexType` as a type in the rest of your schema.\n\n#### RegularExpression options\n\nThere is an optional third `options` argument to the RegularExpression constructor that can be used like this:\n\n```javascript\nconst options = {\n  errorMessage: (regex, value) => {\n    if (process.env.NODE_ENV === 'production')\n      return `Value is invalid format: ${value} `;\n    else\n      return `Value does not match the regular expression ${regex}: ${value}`;\n  },\n};\n\nconst MyRegexType = new RegularExpression('MyRegexType', /^ABC$/, options);\n```\n\n## Why?\n\nThe primary purposes these scalars, really of _all_ types are to:\n\n1.  Communicate to users of your schema exactly what they can expect or to at least _reduce_\n    ambiguity in cases where that's possible. For example if you have a `Person` type in your schema\n    and that type has as field like `ageInYears`, the value of that can only be null or a positive\n    integer (or float, depending on how you want your schema to work). It should never be zero or\n    negative.\n1.  Run-time type checking. GraphQL helps to tighten up the contract between client and server. It\n    does this with strong typing of the _interface_ (or _schema_). This helps us have greater\n    confidence about what we're receiving from the server and what the server is receiving from the\n    client.\n\nThis package adds to the base options available in GraphQL to support types that are reasonably\ncommon in defining schemas or interfaces to data.\n\n## The Types\n\n### DateTime\n\nUse real JavaScript Dates for GraphQL fields. Currently you can use a String or an Int (e.g., a\ntimestamp in milliseconds) to represent a date/time. This scalar makes it easy to be explicit about\nthe type and have a real JavaScript Date returned that the client can use _without_ doing the\ninevitable parsing or conversion themselves.\n\n### NonNegativeInt\n\nIntegers that will have a value of 0 or more. Uses [`parseInt()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt).\n\n### NonPositiveInt\n\nIntegers that will have a value of 0 or less. Uses [`parseInt()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt).\n\n### PositiveInt\n\nIntegers that will have a value greater than 0. Uses [`parseInt()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt).\n\n### NegativeInt\n\nIntegers that will have a value less than 0. Uses [`parseInt()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt).\n\n### NonNegativeFloat\n\nFloats that will have a value of 0 or more. Uses [`parseFloat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat).\n\n### NonPositiveFloat\n\nFloats that will have a value of 0 or less. Uses [`parseFloat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat).\n\n### PositiveFloat\n\nFloats that will have a value greater than 0. Uses [`parseFloat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat).\n\n### NegativeFloat\n\nFloats that will have a value less than 0. Uses [`parseFloat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat).\n\n### EmailAddress\n\nA field whose value conforms to the standard internet email address format as specified in\n[RFC822](https://www.w3.org/Protocols/rfc822/).\n\n### URL\n\nA field whose value conforms to the standard URL format as specified in\n[RFC3986](https://www.ietf.org/rfc/rfc3986.txt).\n\n### PhoneNumber\n\nA field whose value conforms to the standard E.164 format as specified in\n[E.164 specification](https://en.wikipedia.org/wiki/E.164). Basically this is `+17895551234`.\nThe very powerful\n[`libphonenumber` library](https://github.com/googlei18n/libphonenumber) is available to take\n_that_ format, parse and display it in whatever display format you want. It can also be used to\nparse user input and _get_ the E.164 format to pass _into_ a schema.\n\n### PostalCode\n\nWe're going to start with a limited set as suggested [here](http://www.pixelenvision.com/1708/zip-postal-code-validation-regex-php-code-for-12-countries/)\nand [here](https://stackoverflow.com/questions/578406/what-is-the-ultimate-postal-code-and-zip-regex).\n\nWhich gives us the following countries:\n\n- US - United States\n- UK - United Kingdom\n- DE - Germany\n- CA - Canada\n- FR - France\n- IT - Italy\n- AU - Australia\n- NL - Netherlands\n- ES - Spain\n- DK - Denmark\n- SE - Sweden\n- BE - Belgium\n- IN - India\n\nThis is really a practical decision of weight (of the package) vs. completeness.\n\nIn the future we might expand this list and use the more comprehensive list found [here](http://unicode.org/cldr/trac/browser/tags/release-26-0-1/common/supplemental/postalCodeData.xml).\n\n### RegularExpression\n\nA `GraphQLScalarType` object generator that takes two arguments:\n\n- `name` - The name of your custom type\n- `regex` - The regex to be used to check against any values for fields with this new type\n\n```\nconst MyRegexType = new RegularExpression('MyRegexType', /^ABC$/);\n```\n\n## What's this all about?\n\nGraphQL is a wonderful new approach to application data and API layers that's gaining momentum. If\nyou have not heard of it, start [here](http://graphql.org/learn/) and check out\n[Apollo](http://dev.apollodata.com/) also.\n\nHowever, for all of GraphQL's greatness. It is missing a couple things that we have (and you might)\nfind very useful in defining your schemas. Namely GraphQL has a\n[limited set of scalar types](http://graphql.org/learn/schema/#scalar-types) and we have found there\nare some additional scalar types that are useful in being more precise in our schemas. Thankfully,\nthose sharp GraphQL folks provided a simple way to add new custom scalar types if needed. That's\nwhat this package does.\n\n**NOTE:** We don't fault the GraphQL folks for these omissions. They have kept the core small and\nclean. Arguably not every project needs these additional scalar types. But _we_ have, and now _you_\ncan use them too if needed.\n\n## License\n\nReleased under the [MIT license](https://github.com/okgrow/analytics/blob/master/License.md).\n\n## Contributing\n\nIssues and Pull Requests are always welcome.\n\nPlease read our [contribution guidelines](https://okgrow.github.io/guides/docs/open-source-contributing.html).\n","readmeFilename":"README.md"}