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 🙏

© 2025 – Pkg Stats / Ryan Hefner

schema-filter

v1.0.12

Published

given schema, this package extracts all available queries, mutations, subscriptions and then make list of those to determine whether to use each graphql operation, by using that filters, reduced-schema is generated

Readme

schema-filter

"Tool to reduce graphql schema size"

Given schema, this package extracts all available queries, mutations, subscriptions and then make list of those to determine whether to use each graphql operation, by using that check-list, reduced-schema is generated. Actually-not used operations are not included in final reduced-schema

Examples

Feel free to check example/ You may figure out what's happening there. Given below schema & our generated Query.json, Mutation.json, Subscription.json filter file (which is also generated/updated by schema-filter init command)

type Post {
  id: ID!
  title: String!
  content: String!
}

type Query {
  getPost(id: ID!): Post
  getAllPosts: [Post!]!
}

type Mutation {
  createPost(title: String!, content: String!): Post!
  updatePost(id: ID!, title: String, content: String): Post!
  deletePost(id: ID!): ID!
  updatePostWithInput(id: ID!, data: PostUpdateDataInput): Post
}

type Subscription {
  postCreated: Post!
  postUpdated(id: ID!): Post!
  postDeleted(id: ID!): ID!
}

input PostUpdateDataInput {
  id: ID
  title: String
  content: String
}

This package finally generates below reduced-schema If some types are not used(reachable) in any operations, those types are excluded in reduced-schema (even though not visible in below example for now, feel sory for that, later I will update this example)

Only actually-used operations are included in reduced-schema

type Post {
  id: ID!
  title: String!
  content: String!
}

type Query {
  getPost(id: ID!): Post
}

type Mutation {
  createPost(title: String!, content: String!): Post!
  deletePost(id: ID!): ID!
  updatePostWithInput(id: ID!, data: CustomScalarName): Post
}

type Subscription {
  postDeleted(id: ID!): ID!
}



scalar CustomScalarName

How it works

  1. extracts all available queries, mutations, subscriptions from given schema
  2. generates filters for each operation type (Query, Mutation, Subscription)
  3. generates reduced-schema by using filters
  4. [Further work] you may include/exclude single operation by name in check-list as you wish

Commands

For every command, you should add prefix npx schema-filter to execute To show available commands, execute one of below command after installation

npx schema-filter
npx schema-filter --help

Getting Started

  1. Install package (one of below command)

    yarn add --dev schema-filter
    # npm i --save schema-filter
  2. Add/Adjust below configuration in your package.json

    only schmea-original is "MANDATORY", others are optional

    "schema-filter": {
       // "MANDATORY"
       // give your schema "file" path
       "schema-original":"lib/src/gql/schema.graphql",
          
       // give "directory" path to store filters as you wish
       "filters":"lib/src/schema-filters/",
          
       // give "file" path to store reduced-schema as you wish
       "schema-reduced":"lib/src/gql/schema-reduced.graphql",
    
       // after initialization of filters, there would be new operations
       // for newly added operations, you can set default behavior (whether to incldue or not)
       // for all operation type, default value is `true`
       "batch-setting": {
         "Query": true,
         "Mutation": false,
         "Subscription": true,
       },
      
       // If you need to exclude some input types by name, you can set Regular Expressions.
       // With the given example, you may exclude input types such as "PostUpdateDataInput".
       "input-type-name-regexes-to-remove": ["\\b\\w+(Update)\\w+(Input)\\b"],
      
       // The excluded input type nodes will be replaced with the custom scalar type,
       // and its name could be set here.
       // If you provide "input-type-name-regexes-to-remove", you should provide this field as well.
       "custom-scalar-name": "CustomScalarName"
    }

    Mandatory fields

    [1] schema-orginal : schema file path to reduce

    Optional fields

    [2] filters : directory path to store generated filter files

    • If not given, generated filter files' path are determined by schema-orginal's path
    • Directory will be same with schema-orginal's directory
    • Directory name will be filters and filters will be generated under it.

    [3] schema-reduced : file path to store reduced schema

    • If not given, generated-reduced schema file information is determined by schema-orginal's path
    • Directory will be same with schema-orginal's directory
    • Filename will be schema-reduced.graphql

    [4] batch-setting : default filter value for newly added operations by operation type

    • After initialization of filters, there would be new operations. for newly added operations, you can set default behavior (whether to incldue or not)
    • For all operation type, default value is true

    [5] input-type-name-regexes-to-remove : Regular-Expression-like string values array to exclude some input types by name

    • If you need to exclude some input types by name, you can set Regular Expressions.
    • If you provide this field, you should provide custom-scalar-name as well.

    [6] custom-scalar-name : Custom scalar type name to replace excluded input types

    • The excluded input type nodes will be replaced with the custom scalar type,
    • and its name could be set here.
    • If you provide input-type-name-regexes-to-remove, you should provide this field as well.
  3. Initialize/Update filters

    Below command will generate filters file under generated filters/ directory in schema-orginal's directory or where you set in package.json If already filters are generated, this command will update filters by adding newly added operations, not touching already generated operations

    npx schema-filter init
  4. filter(reduce) schema using filters

    execute below command at project root path

    npx schema-filter:filter
  5. [Further Work] toggle on/off single operation in filters

    How to include operation

    npx schema-filter include {operation-name}
    npx schema-filter include {operation-name} -a # call with -a option to filter schema again using new check-list

    How to exclude operation

    npx schema-filter exclude {operation-name}
    npx schema-filter exclude {operation-name} -a # call with -a option to filter schema again using new check-list
  6. if any change is made in check-list, execute below command to filter schema again

    npx schema-filter filter

Contributions

How to Test Locally

  1. clone this repository

    git clone https://github.com/vetching-corporation/schema-filter.git
  2. check below commands in package.json

    "test:init": "yarn build && node build/index.js init",
    "test:include": "yarn build && node build/index.js include",
    "test:exclude": "yarn build && node build/index.js exclude",
    "test:filter": "yarn build && node build/index.js filter"

How to Build

yarn cb # clean build

Further Requirements?

If you need any extra functionality, please make an issue on github or contact me [[email protected]]