npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphql-scalar-int53

v1.0.0

Published

GraphQL Int53 Scalar Type

Downloads

825

Readme

GraphQL Int53 Scalar Type

GraphQL Int53 is a scalar that matches the behavior of the Int type, but with a range from -(2**53 - 1) to 2**53 - 1. This corresponds to the safe integer range of an IEEE 754 double precision binary floating-point value.

It is meant as a direct alternative to GraphQL Int, which represents a signed 32‐bit numeric non‐fractional value and supports values with a range from -(2**31) to 2**31 - 1.

Why Does This Exist?

There are numerous places where integral values exceed 2 billion:

  • fileSizeInBytes (files larger than 2 gigabytes)
  • millisecondsSinceEpoch (such as JavaScript/Java Date.getDate())
  • secondsSinceEpoch (after 2038, Year 2038 Problem)
  • freeMemoryInBytes (RAM larger than 2 gigabytes)
  • monetaryAmount (as defined by ISO 4217)
  • databaseRowId (more than 2 billion database rows)
  • youtubeVideoViewCount (currently over 20 videos have this)
  • facebookMonthlyActiveUserCount (reaching over 2 billion)

These values could be represented by Float, but that would be confusing as they are integers, and would be inefficient in programming languages where there is a natural 64-bit integer type. They could also be represented by String, but that would mean an additional parsing and validation step. These values could also be represented by a 64-bit integer, but that would be problematic for JavaScript, Lua and other languages which use an IEEE 754 double precision binary floating-point value as their primary number type.

While somewhat unconventional, the 53-bit integer is a "least common denominator" type that can easily be supported by all programming languages.

Installation

npm install --save graphql-scalar-int53

Usage

import { graphql, buildSchema } from 'graphql';
import GraphQLInt53 from 'graphql-scalar-int53';

const schema = buildSchema(`
scalar Int53
type Query {
    output: Int53
    inputVariable(value: Int53): Int53
    inputLiteral(value: Int53): Int53
}
`);

const query = `
query ($value: Int53) {
    output
    inputVariable(value: $value)
    inputLiteral(value: 9876504321)
}
`;

const root = {
    output: 9876504322,
    inputVariable: ({value}) => value,
    inputLiteral: ({value}) => value,
}

graphql(schema, query, root, null, {value: 98765043223}).then(console.log);

// Outputs:
// { data:
//    { output: 9876504322,
//      inputVariable: 98765043223,
//      inputLiteral: 9876504321 } }