Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Deno 7 min read How-to mediumAdept

How to Build a GraphQL Server with Deno

A GraphQL API server can be built in Deno with the std HTTP Server, the gql middleware, graphql_tools' makeExecutableSchema and graphql_tag. The walkthrough starts with a "Hello, World!" query served at /graphql with GraphiQL enabled, then refactors into separate type definition and resolver files. The expanded version adds Postgres-backed queries (allDinosaurs, oneDinosaur) and an addDinosaur mutation using deno-postgres connection pools and tagged-template SQL. It runs with the --allow-net and --allow-env permission flags.

Related posts

  • Persist Data in Deno with npm using Prisma, Mongoose, Apollo, and more.

    Deno mediumAdept

    Deno's npm: specifiers let you use popular data-layer packages directly, with Deno's opt-in permission flags limiting what a possibly compromised dependency can reach, such as environment variables holding database credentials. Three quick-start walkthroughs follow. Prisma is initialized against a Supabase PostgreSQL database and routed through Prisma Data Platform's Data Proxy. A Mongoose schema with validations writes to and reads from MongoDB. An Apollo GraphQL server defines typeDefs and resolvers over a static dataset.

  • pg_graphql: A GraphQL extension for PostgreSQL

    Supabase mediumAdept

    pg_graphql is an open-source PostgreSQL extension, written in C and SQL, that reflects a GraphQL schema from existing tables and resolves queries entirely inside the database. Supabase built it because its 1 GB free-tier VMs had no memory left for a separate GraphQL process like Graphile or Hasura. Each GraphQL request is transpiled into a single SQL statement that aggregates results as JSON. This avoids N+1 queries, respects row level security, and gives multi-operation requests transactional semantics. Pagination follows the Relay connection spec using keyset pagination, the API is one SQL function (gql.resolve) exposed over HTTP via PostgREST, and a benchmark shows about 2,205 requests/second on a 4-core machine.

  • How pg_graphql works

    Supabase mediumAdept

    pg_graphql is a Rust-based Postgres extension that reflects the SQL schema as a GraphQL schema and serves queries through a `graphql.resolve` SQL function, with no separate server. A request is tokenized and parsed into an AST with the graphql-parser crate, then validated against the GraphQL spec using a reflected schema built from system catalogs. That schema is memoized and reloaded only when the search path, role or schema version changes. Validated queries become builder objects that emit SQL, with quote_ident/quote_literal guarding against injection, and the SQL returns jsonb that is passed back to the client as JSON.

  • Build a Database App with Drizzle ORM and Deno

    Deno mediumAdept

    Drizzle ORM can be used from Deno via npm compatibility to get type-safe CRUD access to PostgreSQL. The walkthrough installs drizzle-orm, drizzle-kit and pg, configures drizzle.config.ts with a DATABASE_URL, and shows two schema paths: introspecting an existing database with `drizzle-kit pull` or defining pgTable schemas in TypeScript and generating migrations with `drizzle-kit generate`. It then builds helper functions for inserting, querying, updating and deleting rows across two related tables using a pg Pool-backed Drizzle client, with the Deno flags (--env, --node-modules-dir) needed to make drizzle-kit work.

  • Build a Typesafe API with tRPC and Deno

    Deno mediumAdept

    tRPC lets a Deno server and client share types through an exported router type, with no schema declarations or code generation. The tutorial installs tRPC v11 and Zod from npm, then builds a file-backed dinosaur API with query, mutation and async-iterable streaming procedures, served by tRPC's standalone HTTP adapter. The client uses splitLink with the batch-stream and subscription links and gets compile-time checking from the imported AppRouter type. Passing a number instead of a string shows Zod rejecting the input at runtime with an invalid_type error.

The quest for software engineering knowledge.

Look:
Layout: