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 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphql-schema-transpiler

v1.0.1

Published

Transpile Your GraphQL Schema To Support Type Inheritance

Downloads

1

Readme

graphql-schema-transpiler

Transpile Your GraphQL Schema To Support Type Inheritance This is a transpiler to allow graphql schema to have inheritance between type, input and interface. Allows single/multiple inheritance among type, input, and interface to reduce/elimate repeated code and make writing schema much easier and cleaner.

Features

  • Inheritance for type, input, interface
  • When implements interface, all fields are copied over
  • Allow inheritance between type and input

Installation

npm install graphql-schema-transpiler --save

API

transpileSchema(schema[, options])

Transpile the schema to stardard GraphQL Schema.

schema

string - schema string to transpile

option

options.addMissingTypesAndInputs

bool? - When inheriting between type and input, fields will be copied with the correct type. Fields with output type in parent will be changed to input type when copied to child of input type

options.debug

bool? - enable debug log

How To Use It

const { transpileSchema } = require('graphql-schema-transpiler');
//or
// import { transpileSchema } from 'graphql-schema-transpiler';

const schema = `

interface Searchable {
  searchQuery: String!
}

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

type Author extends Person implements Searchable {
  email: String
}

type Book implements Searchable {
  id: Int!
  title: String!
  authors: [Author] 
}

# provide default to override inheritted field
input BookInput extends Book {
  id: Int
}

`

//transpile schema string
const transpiledSchema = transpileSchema(schema, {
  addMissingTypesAndInputs: true,
});

//will transpile into
const transpiledSchema = `

interface Searchable {
  searchQuery: String!
}

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

type Author implements Searchable {
  email: String
  firstName: String!
  middleName: String
  lastName: String!
  searchQuery: String!
}

type Book implements Searchable {
  id: Int!
  title: String!
  authors: [Author]
  searchQuery: String!
}

# provide default to override inheritted field
input BookInput {
  id: Int
  title: String!
  authors: [AuthorInput]
  searchQuery: String!
}

input AuthorInput implements Searchable {
  email: String
  firstName: String!
  middleName: String
  lastName: String!
  searchQuery: String!
}

`

Type Inheritance

Single Inheritance

const schema = `

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

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

Multiple Inheritance

const schema = `

type Node {
  id: ID!
}

type Address {
  streetAddress: String
  city: String
  state: String
}

type Person extends Node, Address {
}

`

Inheritance Between Type And Input

const schema = `

input Address {
  id: Int!
  streetAddress: String
  city: String
  state: String
}

type AddressInput extends Address {
  id: Int
}

`

Interface Inheritance

const schema = `

interface Element {
  id: ID!
}

interface DomElement extends Element {
  path: String!
}

`

Implementation

const schema = `

interface Element {
  id: ID!
}

type DomElement implements Element {
  path: String!
}

`

//will transpile into
const transpiledSchema = `

interface Element {
  id: ID!
  name: String!
}

type DomElement implements Element {
  id: ID!
  name: String!
  path: String!
}

`