graphql-schema-transpiler

raw JSON →
1.0.1 verified Fri May 01 auth: no javascript

A transpiler that extends standard GraphQL schema syntax to support type inheritance among `type`, `input`, and `interface` definitions, allowing single and multiple inheritance to reduce boilerplate. Version 1.0.1 is the latest stable release; no active development or release cadence is documented. Unlike GraphQL tools that rely on code-first approaches or schema stitching, this package operates purely at the schema text level, making it simple to integrate into existing build pipelines. It also supports field type conversion when inheriting between `type` and `input` schemas.

error Cannot find module 'graphql-schema-transpiler' or its corresponding type declarations.
cause Package lacks TypeScript type definitions; TypeScript strict mode might not resolve module.
fix
Install @types/graphql or add custom typings: declare module 'graphql-schema-transpiler';
error Uncaught TypeError: transpileSchema is not a function
cause CommonJS require used without destructuring, or wrong import syntax.
fix
Use const { transpileSchema } = require('graphql-schema-transpiler'); or import { transpileSchema } from 'graphql-schema-transpiler';
error Maximum call stack size exceeded
cause Circular inheritance in schema definition.
fix
Remove circular extends clauses from schema types.
gotcha Field type conversion from output to input types when inheriting from type to input may produce unexpected results if unmapped fields exist.
fix Check generated input types for correctness; use `addMissingTypesAndInputs: false` to skip auto-conversion.
gotcha Circular inheritance (e.g., type A extends B, B extends A) may cause infinite recursion or stack overflow.
fix Avoid circular dependencies; validate schema before transpilation.
gotcha Multiple inheritance order matters: fields from later parents may override earlier ones if duplicates exist. Not explicitly documented.
fix Ensure field names are unique across parent types or rely on first-come-first-served behavior.
gotcha Input types inherited from type definitions may lose non-null constraints if child specifies default values.
fix Review generated input types for nullability changes; override fields explicitly.
npm install graphql-schema-transpiler
yarn add graphql-schema-transpiler
pnpm add graphql-schema-transpiler

Transpile a GraphQL schema with type inheritance to standard GraphQL, creating a new schema string with all inherited fields copied.

import { transpileSchema } from 'graphql-schema-transpiler';

const schema = `
type Person {
  firstName: String!
  lastName: String!
}

type Employee extends Person {
  jobTitle: String!
}
`;

const transpiled = transpileSchema(schema, {
  addMissingTypesAndInputs: true,
});

console.log(transpiled);
/* Output:

type Person {
  firstName: String!
  lastName: String!
}

type Employee {
  jobTitle: String!
  firstName: String!
  lastName: String!
}
*/