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 🙏

© 2026 – Pkg Stats / Ryan Hefner

codegen-graphql-scalars-config

v0.1.0

Published

This utility ensures that custom GraphQL scalar types are correctly inferred by the GraphQL code generator. It helps you set up and import scalars while defining their input/output mappings.

Downloads

3

Readme

GraphQL Scalars Configuration

This utility ensures that custom GraphQL scalar types are correctly inferred by the GraphQL code generator. It helps you set up and import scalars while defining their input/output mappings.

Installation

After setting up GraphQL Codegen, install this package:

npm install codegen-graphql-scalars-config

Usage

Use createScalarConfiguration to define scalar types and their imports. The from field is optional; by default, it pulls from graphql-scalars. The as field is also optional; if not provided, it will default to GraphQL{name} (e.g., GraphQLByte for the scalar type Byte).

Use the output from createScalarConfiguration in your GraphQL Codegen configuration to automatically import scalar types and define their mappings.

import { CodegenConfig } from "@graphql-codegen/cli";
import { extractScalarTypeDefs } from "graphql-scalars-type-defs-extractor";
import { createScalarConfiguration } from "codegen-graphql-scalars-config";

const scalarTypesPath = extractScalarTypeDefs({
  output: "scalar-types.generated.graphql",
  scalars: ["Byte", "CountryName", "Date"],
});

const scalarSetup = createScalarConfiguration([
  { name: "Byte", as: "GraphQLByte" },
  { name: "CountryName" },
  { name: "Date" },
  { name: "Foo", as: "GraphQLFoo", from: "./custom-scalars" }, // Custom import (NB: this path should be relative to the generated types path)
]);

const config: CodegenConfig = {
  overwrite: true,
  schema: ["./src/**/*.ts", scalarTypesPath],
  generates: {
    "src/types/resolvers-types.generated.ts": {
      config: {
        scalars: {
          ID: { input: "string", output: "string | number" },
          ...scalarSetup.scalarsConfig,
        },
      },
      plugins: [
        { add: { content: scalarSetup.imports.join("\n") } },
        "typescript",
        "typescript-resolvers",
      ],
    },
  },
};

export default config;

Once you’ve set up your configuration, run the code generator, and your correctly typed scalars will be included in the generated types:

npx graphql-codegen

API Reference

createScalarConfiguration

function createScalarConfiguration(
  imports: ScalarImport[]
): ScalarConfigurationResult;
  • Parameters:
    • imports: An array of objects defining the custom scalar types.
      • name: The name of the scalar (e.g., "Byte").
      • from (optional): The package where the scalar is imported from (defaults to "graphql-scalars").
      • as (optional): The alias to import the scalar as (e.g., "GraphQLByte"). If not provided, it will default to "GraphQL{name}" (e.g., "GraphQLByte" for the scalar Byte).
  • Returns:
    • imports: An array of import statements for the scalars.
    • scalarsConfig: A mapping of scalar names to their respective input/output type definitions.

License

This project is licensed under the MIT License.