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

@shane32/graphql-codegen-near-operation-file-plugin

v1.0.7

Published

A plugin for [GraphQL Code Generator](https://www.graphql-code-generator.com/) that exports GraphQL documents from a generated file adjacent to where they were defined.

Readme

@shane32/graphql-codegen-near-operation-file-plugin

A plugin for GraphQL Code Generator that exports GraphQL documents from a generated file adjacent to where they were defined.

NPM Version License: MIT

Installation

npm install @shane32/graphql-codegen-near-operation-file-plugin

Purpose

This plugin helps manage GraphQL operations in a more organized way by:

  1. Creating .g.ts files adjacent to your GraphQL operation files
  2. Exporting the generated document constants from these files
  3. Maintaining proper relative imports from the main generated file

This approach keeps your GraphQL operations close to where they are used, making your codebase more maintainable and easier to navigate.

Usage

Update your codegen.ts configuration file to include this plugin in your client preset:

import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  schema: 'schema.graphql',
  documents: ['src/**/*.tsx'],
  generates: {
    './src/gql/': {
      preset: 'client',
      plugins: ['@shane32/graphql-codegen-near-operation-file-plugin'],
      presetConfig: {
        gqlTagName: 'gql'
      }
    }
  }
};

export default config;

Configuration

The plugin supports the following configuration options:

includeFileExtension

  • Type: boolean
  • Default: false

When set to true, the generated import statements will include the file extension (e.g., "../gql/graphql.ts" instead of "../gql/graphql").

fileHeader

  • Type: string
  • Default: "This file was automatically generated based on {filename}"

Specifies a custom header comment to be added at the top of each generated file. The placeholder {filename} will be replaced with the name of the source file.

Example:

const config: CodegenConfig = {
  schema: 'schema.graphql',
  documents: ['src/**/*.tsx'],
  generates: {
    './src/gql/': {
      preset: 'client',
      plugins: ['@shane32/graphql-codegen-near-operation-file-plugin'],
      config: {
        fileHeader: 'Auto-generated from {filename} - DO NOT EDIT'
      },
      presetConfig: {
        gqlTagName: 'gql'
      }
    }
  }
};

To disable the file header, set it to an empty string:

config: {
  fileHeader: ''
}

Example

Given the following structure:

src/
  components/
    UserProfile.tsx  // Contains a GraphQL query
  gql/
    graphql.ts      // Main generated file

If UserProfile.tsx contains:

const GET_USER = gql`
  query GetUser($id: ID!) {
    user(id: $id) {
      id
      name
    }
  }
`;

The plugin will generate:

src/
  components/
    UserProfile.tsx
    UserProfile.g.ts  // Generated file with exports
  gql/
    graphql.ts

Where UserProfile.g.ts contains:

// This file was automatically generated based on UserProfile.tsx
export { GetUserDocument } from "../gql/graphql";

License

MIT