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-compose-mysql

v0.0.7

Published

Generates GraphQL types and resolvers from a MySQL database.

Downloads

17

Readme

graphql-compose-mysql

Generates GraphQL types and resolvers from a MySQL database.

As cherry on the cake, it will also:

  • Create fields to make joins between tables (based on foreign keys detected)
  • Use Facebook's dataloader under the hood to drastically improve querying performance*

*: To avoid incoherent data, dataloaders' caching disabled, only batching feature used.

Installation

yarn install graphql graphql-compose graphql-compose-mysql

Modules graphql and graphql-compose, are located in peerDependencies, so they should be installed explicitly in your app. They have global objects and should not have ability to be installed as submodules.

Sample usage

const { ApolloServer } = require("apollo-server")
const { composeWithMysql } = require("graphql-compose-mysql")

async function main() {
    return composeWithMysql({
        mysqlConfig: {
            host: "localhost",
            port: 3306,
            user: "root",
            password: "secret",
            database: "employees"
        },
    }).then(schema => {
        const server = new ApolloServer({
            schema: schema,
            playground: true,
        })

        server.listen().then(({ url }) => {
            console.log(`🚀 Server ready at ${url}`)
        })
    })
}

main()

mysqlConfig will be used internally to initialize a mysql driver. See Available options here.

Tests

pre-requisites

Start the needed docker containers by issuing a docker-compose up in the /tests/ folder.

It will spin up a MySQL database exposed on the local port 3306 and load it up with employees data from datacharmer/test_db.

You will also get an adminer GUI on the local port 8080.

MySQL employees' database

emp_erd.png

GraphQL schema generated

As you can see, join's fields between tables are also created.

      type current_dept_empT {
        emp_no: Int
        dept_no: String
        from_date: Date
        to_date: Date
      }
      
      scalar Date
      
      type departmentsT {
        dept_no: String
        dept_name: String
      }
      
      type dept_emp_latest_dateT {
        emp_no: Int
        from_date: Date
        to_date: Date
      }
      
      type dept_empT {
        emp_no: Int
        dept_no: String
        from_date: Date
        to_date: Date
        departments(dept_name: String): [departmentsT]
        employees(birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]
      }
      
      type dept_managerT {
        emp_no: Int
        dept_no: String
        from_date: Date
        to_date: Date
        departments(dept_name: String): [departmentsT]
        employees(birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]
      }
      
      type employeesT {
        emp_no: Int
        birth_date: Date
        first_name: String
        last_name: String
        gender: String
        hire_date: Date
      }
      
      type Query {
        current_dept_emp(emp_no: Int, dept_no: String, from_date: Date, to_date: Date): [current_dept_empT]
        departments(dept_no: String, dept_name: String): [departmentsT]
        dept_emp(emp_no: Int, dept_no: String, from_date: Date, to_date: Date): [dept_empT]
        dept_emp_latest_date(emp_no: Int, from_date: Date, to_date: Date): [dept_emp_latest_dateT]
        dept_manager(emp_no: Int, dept_no: String, from_date: Date, to_date: Date): [dept_managerT]
        employees(emp_no: Int, birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]
        salaries(emp_no: Int, salary: Int, from_date: Date, to_date: Date): [salariesT]
        titles(emp_no: Int, title: String, from_date: Date, to_date: Date): [titlesT]
      }
      
      type salariesT {
        emp_no: Int
        salary: Int
        from_date: Date
        to_date: Date
        employees(birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]
      }
      
      type titlesT {
        emp_no: Int
        title: String
        from_date: Date
        to_date: Date
        employees(birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]
      }

Run tests

After docker's containers are started, in root folder run:

yarn test

License

MIT