crystal is a free, open source databases project written in TypeScript and released under MIT. It has 12,931 GitHub stars, 625 forks and 169 open issues, and was last pushed 19 hours ago. On this registry it ranks #64 of 143 tracked projects in Databases, with 5 head-to-head comparisons available.

What is crystal?

Graphile's Crystal is a TypeScript monorepo of MIT-licensed GraphQL tooling for the Node.js and PostgreSQL ecosystems, aimed at developers who want an auto-generated, high-performance GraphQL API over a PostgreSQL database or a faster execution engine for a GraphQL.js schema they already own.

What it is

Crystal is the repository that houses the Graphile packages relating to GraphQL, including packages that relate to those packages in turn. The two headline projects are Grafast, a planning and execution engine for GraphQL, and PostGraphile, a tool for building a GraphQL API backed primarily by a PostgreSQL database. Alongside them sit a set of supporting libraries โ€” @dataplan/pg, @dataplan/json, graphile-export, graphile-config, graphile-build, graphile-build-pg, pg-sql2, pg-introspection, @graphile/lru, eslint-plugin-graphile-export and jest-serializer-graphql-schema โ€” a fair few of which can be used independently of the headline projects. The project is written in TypeScript, licensed under MIT, and documented at graphile.org.

The concrete problem it solves is the cost of wiring GraphQL to a database by hand. PostGraphile takes a PostgreSQL database and treats it as the source of truth for an automatically generated GraphQL API, which can still be customised and extended significantly, so a team does not have to hand-write a resolver layer that mirrors its schema. Grafast attacks the same cost from the execution side: it is a drop-in replacement for the execute method from GraphQL.js, and by moving from traditional resolvers to Grafast "plan resolvers" it uses the declarative nature of a GraphQL request to execute business logic more efficiently, reducing server load. Where a generated API later needs to stand on its own, graphile-export can export an in-memory, dynamically constructed GraphQL schema to raw JavaScript source that can be imported and executed.

Key capabilities

  • Grafast provides a standalone planning and execution engine that drops into the execute method of GraphQL.js, with plan resolvers replacing traditional resolvers.
  • PostGraphile generates a well-structured GraphQL API from a PostgreSQL database, and graphile-export can eject that in-memory schema to raw JavaScript source for self-managed operation.
  • graphile-build constructs a GraphQL.js schema from plugins, and graphile-build-pg adds plugins that understand @dataplan/pg services and generate types, relations and mutations for database resources.
  • @dataplan/pg supplies plan classes for interacting with PostgreSQL, and @dataplan/json supplies plan classes for encoding and decoding JSON.
  • pg-sql2 builds highly dynamic, SQL-injection-proof PostgreSQL queries using tagged template literals, while pg-introspection is a strongly typed PostgreSQL introspection library generated from the PostgreSQL documentation.
  • graphile-config handles plugins, presets and configuration files as a universal configuration layer for Graphile software, with eslint-plugin-graphile-export and jest-serializer-graphql-schema supporting code and snapshot workflows.
  • @graphile/lru is an obsessively performant least-recently-used cache with a deliberately tiny feature set; the README states most users want lru-cache instead.

Who uses it and how

  • Teams that already have a PostgreSQL database and want to stand up a GraphQL API from it with low effort, using the database as the source of truth and customising the generated schema afterwards.
  • Developers building their own GraphQL schemas who adopt Grafast as a drop-in replacement for GraphQL.js execute to gain efficiency without large extra effort.
  • Projects that want a generated API only as a starting point and then take ownership of it by running graphile-export to produce importable JavaScript source.
  • Applications deployed as Node.js HTTP services, with Express and Koa (including Koa 2) listed among the project topics.
  • Codebases that want shared plugins, presets and configuration files across Graphile-based tools through graphile-config.

Getting started

The repository publishes the Graphile packages directly, with grafast, postgraphile and graphile-config among the entry points and full documentation hosted at graphile.org; PostGraphile V4 remains available on the legacy branch. The README excerpt provided here does not include install, run or deploy commands, so those must be taken from the project documentation.

How it compares

Within the GraphQL.js ecosystem, Grafast positions itself as a drop-in replacement for the built-in execute method rather than a separate runtime, which lets existing schemas adopt it incrementally. For caching, the README does not claim @graphile/lru as a general-purpose choice and explicitly points users towards lru-cache for typical needs.

When to use it โ€” and when not to

The main value in PostGraphile depends on operating a PostgreSQL database, so a self-hoster must be prepared to run and manage that database, and there is no hosted or container-based deployment option described in the facts. Teams that want a fully managed GraphQL service, or that do not use PostgreSQL, will not get the core benefit, and @graphile/lru should be avoided as a general LRU cache because its feature set is knowingly narrow. The repository is a monorepo whose packages differ in scope and maturity, PostGraphile V4 lives on a separate legacy branch rather than in the main line, and the project carries 169 open issues, so adopters should expect to track version splits and read per-package documentation rather than assume uniform behaviour.

project readme (upstream, from github) โ€” read inline

๐Ÿ”ฎ Graphile's Crystal Monorepo

GitHub Sponsors Discord chat room Follow Follow

At Graphile we love GraphQL so much we named ourself for our love of it! This repository houses many of the Graphile packages that relate to GraphQL (or relate to the packages that relate to GraphQL, or relate to those package...); the two headline projects are Grafast and PostGraphile but there's many other packages, a fair few of which can be used independently - see below for more details.

Grafast: A cutting-edge planning and execution engine for GraphQL.js โ”€ use this as a drop-in replacement for the execute method from GraphQL.js and by moving from traditional resolvers to Grafast "plan resolvers" you'll be able to leverage the declarative nature of GraphQL requests to execute your business logic in the most efficient way, leading to reduced server load and happier customers. Use this if you're building your own GraphQL schemas and want the best performance and efficiency without having to put much extra effort in.

PostGraphile: An incredibly low-effort way to build a well structured and high-performance GraphQL API backed primarily by a PostgreSQL database. Our main focusses are performance, automatic best-practices and customisability/extensibility. Use this if you have a PostgreSQL database and you want to use it as the "source of truth" for an auto-generated GraphQL API (which you can still make significant changes to). NOTE: thanks to graphile-export you can also use this as a starting point for an API that you then manage yourself.

โžก๏ธ For PostGraphile V4 see the legacy branch

Project summaries

Here's a rough breakdown of the main packages:

  • grafast - standalone cutting-edge planning and execution engine for GraphQL; see above for full description.
  • graphile-export - a package that can (under the right circumstances) export an in-memory dynamically-constructed GraphQL schema to raw JavaScript source code that can be imported and executed
  • jest-serializer-graphql-schema - a simple Jest serializer that understands GraphQL schemas and thus does not fill snapshots with \"\"\" etc.
  • graphile-config - a module that handles the plugins, presets and configuration files for Graphile software - a universal configuration layer.
  • graphile-build - a system for building a GraphQL.js schema from "plugins", particularly useful for auto-generated GraphQL APIs (e.g. PostGraphile uses this) but also useful for hand-rolled schemas that have a lot of modular but widely-used concerns such as connections, naming, etc.
    • graphile-build-pg - plugins for graphile-build that understand @dataplan/pg (i.e. PostgreSQL) services and can generate types, relations, mutations, etc for these database resources.
  • @graphile/lru - an obsessively performant least-recently-used cache (possibly the fastest general purpose LRU cache in Node.js) with a ridiculously tiny feature set; you almost certainly want @isaacs' lru-cache instead of this.
  • pg-sql2 - a library for building highly dynamic SQL-injection-proof PostgreSQL queries using tagged template literals.
  • pg-introspection - a strongly typed introspection library for PostgreSQL, generated from the PostgreSQL documentation to provide up-to-date details of each introspection field.
  • postgraphile - pulls most of the above technologies together; see above for full description.

Crowd-funded open-source software

To help us develop this software sustainably, we ask all individuals and businesses that use it to help support its ongoing maintenance and development via sponsorship.

Click here to find out more about sponsors and sponsorship.

And please give some love to our featured sponsors ๐Ÿคฉ:

* Sponsors the entire Graphile suite

Why the "crystal" monorepo?

Originally what is now Grafast (and was previously DataPlanner) was known by the codename "Graphile Crystal." This lead us to use the ๐Ÿ”ฎ emoji to represent the project in secret before we announced it publicly, as a codeword for those in the know. Now that Grafast is the name for our planning and execution engine and we needed a name for the monorepo that wasn't too GraphQL specific (since there are things in here that aren't strictly related to GraphQL) and we figured that calling it the Crystal monorepo would honour our original nickname for the project. Rumours that the name was inspired by the maintainers' crystal wedding anniversary are greatly exaggerated.

Frequently asked questions

Is crystal free to use?

crystal is open source under the MIT licence. There is no licence fee and no seat count โ€” you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does crystal do?

๐Ÿ”ฎ Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!

What is crystal written in?

crystal is primarily written in TypeScript. Its source is publicly available at https://github.com/graphile/crystal, and it has 12,931 GitHub stars.