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

graphql-stargen

v1.0.9

Published

Generate graphql remote schema from star schema file

Readme

graphql-stargen

Generate graphql remote schema from star schema file

Installation

npm install graphql-stargen --save

Usage

createStarSchema function reads star-yaml file and creates executable GraphQL schema.

Here is a simple GraphQL server example.

import { GraphQLServer } from 'graphql-yoga'
import { createStarSchema } from 'graphql-stargen'

async function run() {
	const schema = await createStarSchema('./staryaml.yaml')

	if(schema == null) {
		throw new Error('no remote schema exists')
	}
	
	const server = new GraphQLServer({ schema })
	server.start({port: 4000}, () => console.log(`Your GraphQL server is running now ...`))
}

run()

star-yaml file looks like that.

apiVersion: v1
kind: Star
tables:
- name: City
  metadata:
    root: true
  definition:
    type: graphql
    url: 'https://evening-scrubland-62386.herokuapp.com/'
    query: 'cities'
  links:
  - to: 'CityEstate'
    as: 'cityEstate'
    sameAt:
      code: cityCode
  - to: Location
    as: citySummary
    sameAt:
      cityKanji: Japanese
- name: CityEstate
  definition:
    type: graphql
    url: 'https://frozen-chamber-61303.herokuapp.com/'
    query: 'cityEstate'
- name: Location
  definition:
    type: graphql
    url: 'https://guarded-sierra-71026.herokuapp.com/'
    query: 'location'

You can serve the following schema on your server.

{
  cities {
    # this represents the type 'City'
    code
    cityKana
    cityKanji
    cityEstate {
      # this represents the type 'CityEstate' linked by a 'cityEstate' field
      year
      value
    }
    citySummary {
      # this represents the type 'Location' linked by a 'citySummary' field
      Area
      Population
      Density
      Japanese
    }
  }
}

Link and custom link function

Link is a field where 2 models connect each other.

Definition

You can define links in your star-yaml file. A field links under one table can include link definitions.

Sample YAML

tables:
- name: City
  metadata:
    root: true
  definition:
    type: graphql
    url: 'https://evening-scrubland-62386.herokuapp.com/'
    query: 'city'
  # links start
  links:  
  - to: 'CityEstate'
    as: 'cityEstate'
    sameAt:
      code: cityCode
  #links end
- name: CityEstate
  definition:
    type: graphql
    url: 'https://frozen-chamber-61303.herokuapp.com/'
    query: 'cityEstate'

Link definition contains of

`to` # another table name with which the link connects
`as` # a new field name of link
`sameAt` 

sameAt is key-value field which means

  <parent field name>: <child field name>

so if you have the definition code: cityCode, you get the following models.

parent object(parent.code == '001')
 └ child object (child.cityCode == '001')

You can define custom link functions other than simple ==(equals to) function.

Custom link function looks like that

{
  <child field name>: (parent, args) => <function which returns child field value condition>
}
const linkFunction = {
  cityEstate: (parent, args) => {
    return {
      cityCode: parent.code.substr(0,5) // Truncate string before 5th charactor.
    }
  }
}

Then you can specify link function objects to createStarSchema's second argument.

await createStarSchema('./staryaml4.yaml', linkFunction)

How to work

Query to GraphQL servers

  • Query of root model
    • Fragment generation (for response and child query parameter)
    • Delegation to root model server
  • Query of child models
    • Parameter genration with parent model
    • Delegation to child model server
    • Batch query in case that batching parameter function is defined

ToDo

  • Fix AST errors with some GraphQL API sites.