Automatically create a GraphQL server from a sqlite database
Branch: master
Clone or download
Latest commit bca5bc9 Feb 16, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode it works Nov 20, 2017
src Mutations for poly associations #1 Jan 10, 2018
.babelrc it works Nov 20, 2017
.editorconfig it works Nov 20, 2017
.gitignore coverage Nov 22, 2017
.npmignore Update .npmignore Feb 9, 2018
.prettierrc it works Nov 20, 2017
.travis.yml Test against node 8 and 9 Jan 19, 2018
LICENSE Create LICENSE Nov 20, 2017 Readme #1 Jan 10, 2018
package-lock.json 1.5.0 Jan 10, 2018
package.json 1.5.0 Jan 10, 2018

tuql build status Coverage Status

Pronounced: Too cool

tuql is a simple tool that turns a sanely formatted sqlite database into a graphql endpoint. It tries to infer relationships between objects, currently supporting belongsTo, hasMany and belongsToMany. It also forms the basic mutations necessary to create, update, and delete objects, as well as assoicate many-to-many relationships.


npm install -g tuql


tuql --db path/to/database.sqlite

You can also optionally set the port and enable graphiql:

tuql --db path/to/database.sqlite --port 8888 --graphiql

Or, you can use a sql file with statements to build up an in-memory database:

tuql --infile path/to/db_dump.sql --graphiql

If you'd like to print out the schema itself, use:

tuql --db path/to/database.sqlite --schema

Or send it to a file:

tuql --db path/to/database.sqlite --schema > schema.graphql

How it works

Imagine your sqlite schema looked something like this:

posts users categories category_post
id   id id category_id
user_id username title post_id

tuql will automatically define models and associations, so that graphql queries like this will work right out of the box:

  posts {
    user {
    categories {

tuql works one of two ways. It prefers to map your schema based on the foreign key information in your tables. If foreign keys are not present, tuql assumes the following about your schema in order to map relationships:

  1. The primary key column is named id or thing_id or thingId, where thing is the singular form of the table name. Example: For a table named posts, the primary key column should be named id, post_id or postId.
  2. Similarly, foreign key columns should be thing_id or thingId, where thing is the singular form of the associated table.
  3. For many-to-many associations, the table name should be in the form of foo_bar or bar_foo (ordering is not important). The columns should follow the same pattern as #2 above.