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

graphql-extend-input

v1.1.1

Published

Allowing Input to be extended

Readme

graphql-extend-input

npm version Licence Github issues Github stars

Extend graphql Inputs.

Why?

The Simple answer is, extend input MyInput is not part of the GraphQL specs. So, let's say you need to add specific fields to an Input on a remote fetched schema. In this case, you'll have to actually rewrite whole input schema, so now we have this duplication and it's really hard to maintain. This happens quite often if you are to build a graphql gateway and you need to merge the schemas from graphql microservices. Bonus feature extend enum also available.

Hopefully this will be introduced into the specs sooner or later!

What's the goal?

  • Get the statement extend input MyInput and NewInput extend input MyInput to work.
  • Don't touch on the AST or GraphQL objects directly, this should work on top of the work already done by other contributors so let's try to make it simple, even if that means fewer features.
  • Use graphql/utilities as much as possible.

How to use

  • [NewName] extend <input|enum> ObjectToExt[, AnotherObjectToExt, ...]
  • A complex example would be: NewInput extends input MyInput1, MyInput2, MyInput3 {}. This will only return text (GraphQL language) with a new input type called NewInput.

Install

npm i graphql-extend-input --save-prod

Getting partial changes/creations

import gqlExtI from 'graphql-extend-input';

// Schema representing a remote fetched schema
// this can either be a string or a GraphQLSchema object
const remoteFetchedSchema = `
  scalar Date

  input BookInput {
    title: String!
    date: Date
  }

  type Book {
    id: ID!
    title: String
    author: String
    price: Float
  }

  type Query {
    getBooks(filter: [BookInput]!): Book
  }
`;

const newSchema = gqlExtI(remoteFetchedSchema, `
  extend input BookInput {
    author: String
    price: Float
  }
`);
console.log(newSchema);
/** Output:

  input BookInput {
    author: String
    price: Float
    title: String!
    date: Date
  }
*/

So you can now use newSchema and merge it with remoteFetchedSchema. It would look something like:

import { mergeSchemas } from 'graphql-tools';

const mergedSchemas = mergeSchemas({
  schemas: [
    remoteFetchedSchema,
    newSchema
  ],
  resolvers: (mergeInfo) => ({
    // new/overwrite resolvers
  }),
  onTypeConflict: (left, right) => {
    // for this example we need to return right!
    return right;
  }
});

Extending and creating a new Input

If you don't need to mess with existing Inputs you could also do the following.

const newSchema = gqlExtI(remoteFetchedSchema, `
  NewBookInput extend input BookInput {
    author: String
    price: Float
  }

  extend type Query {
    newGetBooks(filter: [NewBookInput]!): Book
  }
`);

console.log(newSchema);
/** Output:

  input NewBookInput {
    author: String
    price: Float
    title: String!
    date: Date
  }
  extend type Query {
    newGetBooks(filter: [NewBookInput]!): Book
  }
*/

Get the complete resulting schema

const newSchema = gqlExtI(remoteFetchedSchema, `
  extend input BookInput {
    author: String
    price: Float
  }
`, true); // just need to pass true on the last param

console.log(newSchema);
/** Output:

  scalar Date
  input BookInput {
    author: String
    price: Float
    title: String!
    date: Date
  }
  type Book {
    id: ID!
    title: String
    author: String
    price: Float
  }
  type Query {
    getBooks(filter: [BookInput]!): Book
  }

*/

Multiple extends - similar to union


const remoteFetchedSchema = `
  input PersonInput {
    firstname: String!
    lastname: String!
  }

  input AddressBookInput {
    street: String!
    phone: String!
  }
`;

const newSchema = gqlExtI(remoteFetchedSchema, `
  EmployeeInput extend input PersonInput, AddressBookInput {
    salary: Float!
    department: String!
  }

  extend type Query {
    getEmployNumber(input: EmployeeInput): Int!
  }
`);

console.log(newSchema);
/** Output:

  input EmployeeInput {
    salary: Float!
    department: String!
    street: String!
    phone: String!
    firstname: String!
    lastname: String!
  }
  extend type Query {
    getEmployNumber(input: EmployeeInput): Int!
  }

*/

Into the wild plus extend enum

const remoteFetchedSchema = `
  input TVShowInput {
    title: String!
    duration: Int!
  }

  input TVShowCastInput {
    castMemberName: String!
  }

  enum TVShows {
    lost
    walking_dead
  }

  enum BestTVShows {
    got
    breaking_bad
    black_mirror
    mr_robot
  }
`;

const newSchema = gqlExtI( remoteFetchedSchema,
  `
  type TvShow {
    title: String!
    duration: Int!
    cast: [String!]!
  }

  TVShowSearchInput extend input TVShowInput, TVShowCastInput {
    tvshow: AllTVShowsEnum
  }

  AllTVShowsEnum extend enum TVShows, BestTVShows {}

  extend type Query {
    searchTVShows(input: TVShowSearchInput): [TVShow]
    getTVShow(input: AllTVShowsEnum) TVShow
  }
`
);

console.log(newSchema);
/** Output:

  input TVShowSearchInput {
    tvshow: AllTVShowsEnum
    castMemberName: String!
    title: String!
    duration: Int!
  }
  enum AllTVShowsEnum {
    got
    breaking_bad
    black_mirror
    mr_robot
    lost
    walking_dead
  }
  type TvShow {
    title: String!
    duration: Int!
    cast: [String!]!
  }
  extend type Query {
    searchTVShows(input: TVShowSearchInput): [TVShow]
    getTVShow(input: AllTVShowsEnum) TVShow
  }
*/

Work in progress

  • Maybe support extend enum also or maybe that will be for another repo. ✔️
  • More real world examples and tests.

Important note:

Unfortunately I don't do open-source for a living, not that I would mind :), so if you find a bug or have any suggestion to improve this module you're very welcome to contribute.