Sourcemap Explorer
Stack · npm package

gel

The official Node.js client library for Gel

latest 2.2.0· Apache-2.0· 88 versions publishedView on npm

About

The official Node.js client library for Gel

Live mirror of the GitHub README. Updated whenever the repo's default branch changes.

The official Node.js client library for Gel

Build status NPM version Stars

Quickstart   •   Website   •   Docs   •   Discord   •   Twitter

This is the official Gel client library for JavaScript and TypeScript.

If you're just getting started with Gel, we recommend going through the Gel Quickstart first. This walks you through the process of installing Gel, creating a simple schema, and writing some simple queries.

Requirements

  • Node.js 18+
  • For TypeScript users:
    • TypeScript 4.4+ is required

Basic usage

The examples below demonstrate only the most fundamental use cases for this library. Go to the complete documentation site. >

Create a client

A client is an instance of the Client class, which maintains a pool of connections to your database and provides methods for executing queries.

import * as gel from "gel";

const client = gel.createClient();

Configuring the connection

The call to gel.createClient() doesn't require arguments, as the library can determine how to connect to your database using the following mechanisms.

  1. For local development: initialize a project with the gel project init command. As long as the file is within a project directory, createClient will be able to auto-discover the connection information of the project's associated instance. For more information on projects, follow the Using projects guide.

  2. In production: configure the connection using environment variables. (This can also be used during local development if you prefer.) The easiest way is to set the GEL_DSN variable; a DSN (also known as a "connection string") is a string of the form gel://USERNAME:PASSWORD@HOSTNAME:PORT/DATABASE.

For advanced cases, see the DSN specification and Reference > Connection Parameters.

Run a query

import * as gel from "gel";

const client = gel.createClient();
await client.query("select 2 + 2"); // => [4]

Note that the result is an array. The .query() method always returns an array, regardless of the result cardinality of your query. If your query returns zero or one elements, use the .querySingle() method instead. If your query is guaranteed to return exactly one element, use the .queryRequiredSingle() method.

// empty set, zero elements
const q1 = await client.querySingle<string>("select <str>{}");
//    ^? string | null

// one element
const q2 = await client.querySingle<number>("select 2 + 2");
//    ^? number | null

// one element
const q3 = await client.querySingle<{ title: string }>(
//    ^? { title: string } | null
  `select Movie { title }
  filter .id = <uuid>'2eb3bc76-a014-45dc-af66-2e6e8cc23e7e';`,
);

// exactly one element
const q4 = await client.queryRequiredSingle<number>("select 42;");
//    ^? number

Generators

Install the @gel/generate package as a dev dependency to take advantage of Gel's built-in code generators.

npm install @gel/generate  --save-dev

Then run a generator with the following command:

$ npx @gel/generate <generator> [FLAGS]

The following <generator>s are currently supported:

  • queries: Generate typed functions from *.edgeql files
  • interfaces: Generate interfaces for your schema types
  • edgeql-js: Generate the query builder

queries

Run the following command to generate a source file for each *.edgeql system in your project.

$ npx @gel/generate queries

Assume you have a file called getUser.edgeql in your project directory.

// getUser.edgeql
select User {
  name,
  email
}
filter .email = <str>$email;

This generator will generate a getUser.query.ts file alongside it that exports a function called getUser.

import { createClient } from "gel";
import { getUser } from "./getUser.query";

const client = createClient();

const user = await getUser(client, { name: "Timmy" });
//    ^? { name: string; email: string }

The first argument is a Client, the second is the set of parameters. Both the parameters and the returned value are fully typed.

edgeql-js (query builder)

The query builder lets you write queries in a code-first way. It automatically infers the return type of your queries.

To generate the query builder, install the gel package, initialize a project (if you haven't already), then run the following command:

$ npx @gel/generate edgeql-js

This will generate an EdgeQL query builder into the ./dbschema/edgeql-js directory, as defined relative to your project root.

For details on generating the query builder, refer to the complete documentation. Below is a simple select query as an example.

import { createClient } from "gel";
import e from "./dbschema/edgeql-js";

const client = createClient();
const query = e.select(e.Movie, (movie) => ({
  id: true,
  title: true,
  actors: { name: true },
  num_actors: e.count(movie.actors),
  filter_single: e.op(movie.title, "=", "Dune"),
}));

const result = await query.run(client);
result.actors[0].name; // => Timothee Chalamet

For details on using the query builder, refer to the full query builder docs.

Contribute

Contributing to this library requires a local installation of Gel. Install Gel from here or build it from source.

$ git clone git@github.com:geldata/gel-js.git
$ cd gel-js
$ yarn                # install dependencies
$ yarn run build      # build all packages
$ yarn run test       # run tests for all packages

In order to be able to run all tests you need to have gel-server in your path. This can be done by either running tests from within a Python 3.12 virtual environment (you will have it if you built Gel locally), or by installing specific Gel version and then adding its binary path to the GEL_SERVER_BIN environment variable. Check here to find how to get the binary path.

License

gel-js is developed and distributed under the Apache 2.0 license.

Quick facts

Latest version2.2.0
LicenseApache-2.0
AuthorGel
Installnpm install gel
Direct dependencies6

How Sourcemap Explorer detects gel

We catch gel from two complementary signals: bundled source paths and the embedded package.json. Modern bundlers (webpack, Vite, esbuild, Rollup, Turbopack) preserve the original node_modules/gel/ paths inside the JavaScript sourcemap's sources[] array — that's the canonical signal. When the matching package.json is also captured in sourcesContent[], we read the exact version field — patch number included. No regex guessing, no version inference.

  1. 1

    Confirm the site exposes sourcemaps

    In DevTools Network, check the response headers of any application script for `SourceMap` or `X-SourceMap`. Failing that, fetch the script's last 4 KB and look for a `//# sourceMappingURL=` comment.

  2. 2

    Find the package in the bundle

    Open DevTools → Network → reload. Click any application script and look at its sourcemap. Inside, search `sources[]` for entries matching `node_modules/gel/` — every match confirms the package is bundled. The matching `sourcesContent[i]` for `node_modules/gel/package.json` gives you the exact installed version.

  3. 3

    Read the version directly from package.json

    Run `jq -r '. as $m | $m.sources | to_entries[] | select(.value | endswith("node_modules/gel/package.json")) | $m.sourcesContent[.key] | fromjson | .version' bundle.js.map`. Sourcemap Explorer automates the same query in the popup.

Recent versions

Version
Released
0.0.1
2.0.0
2.0.1
2.0.2
2.1.0
2.1.1
2.2.0

FAQ

What is gel used for?

The official Node.js client library for Gel

How can I tell if a website is using gel?

Open the page in Chrome with the Sourcemap Explorer extension installed and read the Stack tab. We catch `gel` from two complementary signals: `node_modules/gel/` paths inside the JavaScript sourcemap, and the embedded `package.json` we read for exact-version detection. Without the extension you can do the same lookup manually in DevTools — the steps are listed in the "How Sourcemap Explorer detects" section above.

What is the latest version of gel?

2.2.0, as published on the npm registry. The "Recent versions" table on this page lists the most recent 7 releases with their release dates. Sourcemap Explorer reports the version actually bundled into a site, which can lag the latest release by months on real-world deployments.

Where can I read more?

Project homepage: https://geldata.com/docs. Source code: https://github.com/geldata/gel-js. Published on npm: https://www.npmjs.com/package/gel. Licensed as Apache-2.0.

Detected by Sourcemap Explorer

When a bundle ships sourcemaps, we read the embedded package.json for gel and report the precise version. Without sourcemaps, an import / require in the page's scripts is enough to flag it.

Install free on Chrome