Light
Dark
System
v4latest
v5dev
v4latest
v3
v2
v1

Generators

The @edgedb/generate package provides a set of code generation tools that are useful when developing an EdgeDB-backed applications with TypeScript/JavaScript.

To get started with generators, first initialize an EdgeDB project in the root of your application. Generators will look for an edgedb.toml file to determine the root of your application. See the Overview page for details on installing

Run a generator with the following command.

npm
yarn
pnpm
Deno
Copy
$ 
npx @edgedb/generate <generator> [options]
Copy
$ 
yarn run -B generate <generator> [options]
Copy
$ 
pnpm exec generate <generator> [options]
Copy
$ 
  
  
  
deno run \
--allow-all \
--unstable \
https://deno.land/x/edgedb/generate.ts <generator> [options]

.. code-tab:: bash
  :caption: bun
Copy
  $ 
bunx @edgedb/generate <generator> [options]

The value of <generator> should be one of the following:

edgeql-js

Generates the query builder which provides a code-first way to write fully-typed EdgeQL queries with TypeScript. We recommend it for TypeScript users, or anyone who prefers writing queries with code.

docs

queries

Scans your project for *.edgeql files and generates functions that allow you to execute these queries in a typesafe way.

docs

interfaces

Introspects your schema and generates file containing TypeScript interfaces that correspond to each object type. This is useful for writing typesafe code to interact with EdgeDB.

docs

The generators require a connection to an active EdgeDB database. It does not simply read your local .esdl schema files. Generators rely on the database to introspect the schema and analyze queries. Doing so without a database connection would require implementing a full EdgeQL parser and static analyzer in JavaScript—which we don’t intend to do anytime soon.

Make sure your development database is up-to-date with your latest schema before running a generator!

If you’re using edgedb project init, the connection is automatically handled for you. Otherwise, you’ll need to explicitly pass connection information via environment variables or CLI flags, just like any other CLI command. See Client Libraries > Connection for guidance.

All generators look at your environment and guess what kind of files to generate (.ts vs .js + .d.ts) and what module system to use (CommonJS vs ES modules). You can override this with the --target flag.

--target ts

Generate TypeScript files (.ts)

--target mts

Generate TypeScript files (.mts) with extensioned ESM imports

--target esm

Generate .js with ESM syntax and .d.ts declaration files

--target cjs

Generate JavaScript with CommonJS syntax and and .d.ts declaration files

--target deno

Generate TypeScript files with Deno-style ESM imports

To see helptext for the @edgedb/generate command, run the following.

Copy
$ 
npx @edgedb/generate --help
Light
Dark
System

We use ChatGPT with additional context from our documentation to answer your questions. Not all answers will be accurate. Please join our Discord if you need more help.