10

GitHub - supabase/pg_graphql: GraphQL support for PostgreSQL

 2 years ago
source link: https://github.com/supabase/pg_graphql
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

pg_graphql


Documentation: https://supabase.github.io/pg_graphql

Source Code: https://github.com/supabase/pg_graphql


Query your existing PostgreSQL database with GraphQL

pg_graphql inspects your PostgreSQL schema and reflects a GraphQL schema with resolvers.

  • Performant: +2k requests/second
  • Always up-to-date: Reflected from the SQL schema
  • Pagination: Relay compliant
  • Serverless: Runs in your database with no additional server required
  • Open Source: Apache License 2.0

pg_graphql is pre-alpha software under active development

Overview

pg_graphql provides an SQL schema -> GraphQL schema reflection engine and an associated GraphQL query -> SQL query transpiler.

The extension keeps schema generation, query parsing, and resolvers all neatly contained on your database. This enables any programming language that can connect to PostgreSQL to query the database via GraphQL with no additional servers, processes, or libraries.

TL;DR

The SQL schema

create table account(
    id serial primary key,
    email varchar(255) not null,
    encrypted_password varchar(255) not null,
    created_at timestamp not null,
    updated_at timestamp not null
);

create table blog(
    id serial primary key,
    owner_id integer not null references account(id),
    name varchar(255) not null,
    description varchar(255),
    created_at timestamp not null,
    updated_at timestamp not null
);

create type blog_post_status as enum ('PENDING', 'RELEASED');

create table blog_post(
    id uuid not null default uuid_generate_v4() primary key,
    blog_id integer not null references blog(id),
    title varchar(255) not null,
    body varchar(10000),
    status blog_post_status not null,
    created_at timestamp not null,
    updated_at timestamp not null
);

Translates into a GraphQL schema exposing each table as a pageable collection with relationships defined by the foreign keys.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK