Graphile Crystal

repository·main·Indexed 11 days ago

https://github.com/graphile/crystal

A monorepo of high-performance tools for building GraphQL APIs, featuring Grafast, a next-generation planning and execution engine designed as a high-efficiency alternative to GraphQL.js. Includes grafserv, a performant Node.js GraphQL server, and specialized data plan modules like @dataplan/pg for PostgreSQL and @dataplan/json for JSON processing. Also provides ruru-components for embedding the Ruru GraphQL IDE into React applications.

Tokens
377.3K
Snippets
1K
Records
1.5K
Agent score
96%

What's inside Crystal

  1. What is Graphile Build

    main

    Graphile Build is a toolkit designed for auto-generating flexible and extensible GraphQL APIs from arbitrary data sources. It uses a plugin-based architecture to allow for easy addition or removal of features, and a behavior system that provides fine-grained control over which features are enabled for specific entities.

    Key characteristics include:

    • Extensibility: A plugin system allows users to write custom or community extensions.
    • Performance: Integration with Grafast allows generated schemas to potentially outperform hand-rolled schemas using traditional resolvers and DataLoader.
    • Dynamic Updates: Plugins can trigger rebuild events when underlying data structures change, allowing the GraphQL schema to be updated without restarting the server.

    A primary example of a system built with this toolkit is PostGraphile, which uses it to build GraphQL APIs from PostgreSQL databases.

  2. Overview of graphile-export

    main

    graphile-export is a utility designed to export an in-memory GraphQL schema (constructed via various tooling) into an on-disk executable schema.

    Key Use Cases

    • Removing Build-Time Dependencies: Export your schema to a format that can be loaded at runtime without requiring the heavy dependencies used to build the schema.
    • Optimizing Runtime: Achieve a highly optimized runtime by using pre-built, on-disk schemas.
    • Schema Conversion: Convert schemas between different schema builders. graphile-export is agnostic to the tool used to build the schema, provided it produces a valid GraphQL.js schema.
  3. Overview of Graphile Export

    main

    Graphile Export allows you to export a GraphQL schema (or other code) as executable JavaScript code. It is designed for schemas that are typically generated in-memory via a framework.

    By exporting the schema as code, you move intensive schema-building processes—such as introspection, looping, computation, and transformation—from startup time to build time. At runtime, you simply execute the final code without needing the underlying logic that shaped it.

    Key Benefits

    • Faster startup time: The schema is ready to run without re-computation.
    • Reduced thundering herd: Prevents mass server restarts from overwhelming external data sources during schema generation.
    • Lower resource usage: Production environments do not need to load or execute the code used to compute the schema, reducing CPU and memory overhead.
    • Fewer runtime dependencies: Build-time systems can be omitted from the production bundle.
    • Improved serverless performance: Enables much faster cold starts in environments like AWS Lambda.

    Compatibility and Usage

    • Tooling Agnostic: It is not limited to Graphile-produced software (like PostGraphile, Graphile Build, or Grafast). It works with any JavaScript-based GraphQL schema that is compatible with the export/import requirements.
    • PostGraphile Users: While Graphile Export is tooling-agnostic, PostGraphile users should also consult the official PostGraphile "Exporting your schema" documentation for specific instructions and warnings.
  4. Introduction to Grafserv

    main

    Grafserv is a high-performance GraphQL server integration library for Node.js. It is powered by Grafast and is designed for extreme speed and efficiency.

    Performance Model

    Unlike traditional GraphQL servers that construct intermediary JavaScript objects before stringifying them into JSON, Grafserv leverages Grafast's unique two-phase execution model:

    1. Execution Phase: Grafast executes the query logic.
    2. Output Phase: The output plan is configured to generate a JSON string directly.

    By streaming this JSON string directly to clients, Grafserv significantly reduces latency, memory allocation, and garbage collection (GC) overhead.

  5. What is Graphile Config?

    main
    Graphile Config is a tool designed for Node.js library authors to make their libraries configurable and extensible. It provides a standardized configuration and plugin interface used across the Graphile suite. It allows for strongly typed configuration, plugin-based extensions, and the ability to bundle options into reusable presets.
  6. Overview of Graphile* utilities

    main

    Graphile* is a collection of utility modules developed for the Graphile suite of open source developer tools. These utilities are designed to be used in various projects to handle common tasks such as configuration, schema exporting, safe code evaluation, dynamic SQL generation, and PostgreSQL introspection.

    Available utilities include:

    • graphile-config: Provides a standard plugin interface and helpers used across the Graphile suite.
    • graphile-export: Enables exporting a GraphQL Schema (or other code) as executable JavaScript code.
    • tamedevil: A module designed to help manage and safely handle eval operations.
    • pg-sql2: Allows for creating highly dynamic SQL in a powerful and flexible manner while preventing SQL injection attacks.
    • pg introspection: A strongly-typed PostgreSQL introspection library built automatically from the PostgreSQL system catalog documentation.
  7. Overview of Graphile's Crystal Monorepo

    main

    The Crystal monorepo contains a suite of packages focused on GraphQL, planning, and execution engines. The two primary headline projects are Grafast and PostGraphile.

    • Grafast: A high-performance planning and execution engine for GraphQL.js. It is designed as a drop-in replacement for the standard GraphQL.js execute method. By using Grafast "plan resolvers" instead of traditional resolvers, you can leverage the declarative nature of GraphQL requests to optimize business logic execution and reduce server load. This is ideal for developers building custom GraphQL schemas who want maximum efficiency.
    • PostGraphile: A tool for building high-performance GraphQL APIs backed by a PostgreSQL database with minimal effort. It uses the database as the "source of truth" to auto-generate the API, while allowing for significant customization and extensibility. You can also use graphile-export to turn a PostGraphile-generated API into a managed codebase.
  8. What is PostGraphile?

    main

    PostGraphile is a high-performance tool for building GraphQL APIs directly from a PostgreSQL database. It automates the creation of a consistent, well-structured GraphQL schema by analyzing your database's tables, relations, functions, indexes, and permissions.

    Key benefits include:

    • Minimal Effort: Automates repetitive schema maintenance.
    • High Performance: Uses the Grafast planning and execution engine to optimize queries and prevent under/over-fetching.
    • Extensibility: Allows you to seamlessly add custom types, fields, and business logic via plugins or database-level extensions.
    • No Lock-in: You can export your generated schema as executable code if you ever need to move away from PostGraphile.
  9. What is Ruru

    main

    Ruru is a distribution of GraphiQL (the GraphQL IDE) designed for enhanced developer experience. Key features include:

    • GraphiQL Explorer integration: Includes the popular explorer plugin.
    • Automatic Schema Hot-reloading: Supports schema updates via the X-GraphQL-Event-Stream header.
    • Ease of Deployment: Optimized for various hosting environments.
    • Grafast Enhancements: Provides specialized debugging tools for <Grafast />-powered servers, such as viewing plan diagrams.
    • Customizability: Designed to be customizable for different workflows.

    Note: <Grafast /> is not required to use Ruru; it can be used with any GraphQL API.