![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@okgrow/graphql-scalars
Advanced tools
A library of custom GraphQL scalar types for creating precise type-safe GraphQL schemas.
npm install --save @okgrow/graphql-scalars
To use these scalars you'll need to add them in two places, your schema and your resolvers map.
In your schema:
scalar DateTime
scalar PositiveInt
scalar NonNegativeInt
scalar PositiveFloat
scalar NonNegativeFloat
scalar EmailAddress
scalar URL
In your resolver map, first import them:
import {
DateTime,
PositiveInt,
PositiveFloat,
NonNegativeFloat,
EmailAddress,
URL,
} from '@okgrow/graphql-scalars';
Then make sure they're in the root resolver map like this:
const myResolverMap = {
DateTime,
PositiveInt,
NonNegativeInt,
PositiveFloat,
NonNegativeFloat,
EmailAddress,
URL,
Query: {
// more stuff here
},
Mutation: {
// more stuff here
},
}
Alternatively, use the default import and ES6's spread operator syntax:
import OKGGraphQLScalars from '@okgrow/graphql-scalars';
Then make sure they're in the root resolver map like this:
const myResolverMap = {
...OKGGraphQLScalars,
Query: {
// more stuff here
},
Mutation: {
// more stuff here
},
}
That's it. Now you can use these scalar types in your schema definition like this:
type Person {
birthDate: DateTime
ageInYears: PositiveInt
heightInInches: PositiveFloat
minimumHourlyRate: NonNegativeFloat
currentlyActiveProjects: NonNegativeInt
email: EmailAddress
homePage: URL
}
These scalars can be used just like the base, built-in ones.
The primary purposes these scalars, really of all types are to:
Person
type in your schema
and that type has as field like ageInYears
, the value of that can only be null or a positive
integer (or float, depending on how you want your schema to work). It should never be zero or
negative.This package adds to the base options available in GraphQL to support types that are reasonably common in defining schemas or interfaces to data.
Use real JavaScript Dates for GraphQL fields. Currently you can use a String or an Int (e.g., a timestamp in milliseconds) to represent a date/time. This scalar makes it easy to be explicit about the type and have a real JavaScript Date returned that the client can use without doing the inevitable parsing or conversion themselves.
Integers that will have a value of 0 or more. Uses parseInt()
.
Integers that will have a value greater than 0. Uses parseInt()
.
Floats that will have a value of 0 or more. Uses parseFloat()
.
Floats that will have a value greater than 0. Uses parseFloat()
.
A field whose value conforms to the standard internet email address format as specified in RFC822.
A field whose value conforms to the standard URL format as specified in RFC3986.
We'd like to keep growing this package, within reason, to include the scalar types that are widely required when defining GraphQL schemas. We welcome both suggestions and pull requests. A couple of ideas we're considering are:
These are easy to add, we just haven't run into cases for them yet.
These both have challenges in terms of making them globally useful so they need a bit of thought.
For PhoneNumber
we can probably just use the E.164 specification
which is simply +17895551234
. The very powerful
libphonenumber
library is available to take
that format, parse and display it in whatever display format you want. It can also be used to
parse user input and get the E.164 format to pass into a schema.
Postal codes are a bit more involved. But, again, it's probably just a really long regex.
GraphQL is a wonderful new approach to application data and API layers that's gaining momentum. If you have not heard of it, start here and check out Apollo also.
However, for all of GraphQL's greatness. It is missing a couple things that we have (and you might) find very useful in defining your schemas. Namely GraphQL has a limited set of scalar types and we have found there are some additional scalar types that are useful in being more precise in our schemas. Thankfully, those sharp GraphQL folks provided a simple way to add new custom scalar types if needed. That's what this package does.
NOTE: We don't fault the GraphQL folks for these omissions. They have kept the core small and clean. Arguably not every project needs these additional scalar types. But we have, and now you can use them too if needed.
Released under the MIT license.
Issues and Pull Requests are always welcome. Please read our contribution guidelines.
FAQs
A collection of scalar types not included in base GraphQL.
The npm package @okgrow/graphql-scalars receives a total of 711 weekly downloads. As such, @okgrow/graphql-scalars popularity was classified as not popular.
We found that @okgrow/graphql-scalars demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.