@gel/generate
v0.7.1
Published
Gel code generators for TS/JavaScript
Readme
@gel/generate: Code generation tools for Gel
The @gel/generate package implements a set of code generation tools that are useful when developing an Gel-backed applications with TypeScript/JavaScript.
Installation
If you're using Deno, you can skip this step.
Install the gel package.
$ npm install gel # npm users
$ yarn add gel # yarn usersThen install @gel/generate as a dev dependency.
$ npm install @gel/generate --save-dev # npm users
$ yarn add @gel/generate --dev # yarn usersRun a generator
Run a generator with the following command.
Node.js
$ npx @gel/generate <generator> [options]Deno
$ deno run --allow-all npm:@gel/generate <generator> [options]The value of <generator> should be one of the following.
queries: This generator scans your project for*.edgeqlfiles and generates a file containing a strongly-typed function for each.edgeql-js: This generator introspects your database schema and generates a query builder.interfaces: This generator introspects your database schema and generates TypeScript interfaces for each object type.
Third-party generators
✨ If you build a code generator for Gel, ping us or open a PR and we'll list it here! ✨
The gel package exports a set of utilities to introspect the schema and analyze queries. We use this same set of tools to implement the first-party generators.
import { createClient, $ } from "gel";
const client = createClient();
const types = await $.introspect.types(client);
// Map<string, Type>
const queryData = await $.analyzeQuery(client, `select 2 + 2`);
// {args: string; result: string; ...}Contributing
If you want to implement a code generator, please open an issue first. This package only contains first-party generators with widespread appeal. From the root directory:
yarn
yarn workspaces run build # build all packagesNavigate into packages/generate:
Build @gel/generate
yarn buildBuild without typechecking (uses esbuild):
yarn build:fastRun a generator:
npx @gel/generate edgeql-js # query builder
npx @gel/generate queries # query filesExecute playground.ts (uses tsx). Useful for testing things quickly in development:
yarn play⚠️ All imports from
"gel"resolve to the local build version of the driver inpackages/gel/dist. This imports the built library, not the so you need to re-runyarn workspace gel buildfor changes to be reflected in your playground code. Runyarn devwatcher insidepackages/gelto rebuild the project anytime you make a change.
Run commands in watch mode. Useful when in development. The following command rebuilds the package and executes the playground whenever a file change is detected.
yarn watch 'yarn build:fast && yarn play`Run tests.
yarn test