-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
242 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: '3' | ||
services: | ||
|
||
test: | ||
container_name: pg_graphql_test | ||
build: | ||
context: .. | ||
dockerfile: ./dockerfiles/db/Dockerfile | ||
command: | ||
- ./bin/installcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
dockerfiles/ | ||
docs/ | ||
pg_graphql.egg-info/ | ||
target/ | ||
nix/ | ||
node_modules/ | ||
results/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Test | ||
on: | ||
pull_request: | ||
push: { branches: master } | ||
|
||
jobs: | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build docker images | ||
run: docker-compose -f .ci/docker-compose.yml build | ||
|
||
- name: Run tests | ||
run: docker-compose -f .ci/docker-compose.yml run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "pg_graphql" | ||
version = "0.5.2" | ||
version = "0.5.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
version: '3' | ||
services: | ||
|
||
db: | ||
container_name: pg_db | ||
build: | ||
context: . | ||
dockerfile: ./dockerfiles/db/Dockerfile | ||
volumes: | ||
- ./dockerfiles/db/setup.sql:/docker-entrypoint-initdb.d/setup.sql | ||
ports: | ||
- 5406:5432 | ||
command: | ||
- postgres | ||
- -c | ||
- wal_level=logical | ||
- -c | ||
- shared_preload_libraries=pg_stat_statements | ||
healthcheck: | ||
test: ["CMD-SHELL", "PGUSER=postgres", "pg_isready"] | ||
interval: 1s | ||
timeout: 10s | ||
retries: 5 | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: graphqldb | ||
|
||
rest: | ||
container_name: pg_postgrest | ||
image: postgrest/postgrest:v10.0.0 | ||
restart: unless-stopped | ||
ports: | ||
- 3001:3000 | ||
environment: | ||
PGRST_DB_URI: postgres://postgres:password@db:5432/graphqldb | ||
PGRST_DB_SCHEMA: public | ||
PGRST_DB_ANON_ROLE: anon | ||
depends_on: | ||
- db | ||
|
||
graphiql: | ||
container_name: pg_graphiql | ||
image: nginx | ||
volumes: | ||
- ./dockerfiles/graphiql:/usr/share/nginx/html | ||
ports: | ||
- 4000:80 | ||
depends_on: | ||
- rest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM postgres:14 | ||
RUN apt-get update | ||
|
||
ENV build_deps ca-certificates \ | ||
git \ | ||
build-essential \ | ||
libpq-dev \ | ||
postgresql-server-dev-14 \ | ||
curl \ | ||
libreadline6-dev \ | ||
zlib1g-dev | ||
|
||
|
||
RUN apt-get install -y --no-install-recommends $build_deps pkg-config cmake | ||
|
||
WORKDIR /home/pg_graphql | ||
|
||
ENV HOME=/home/pg_graphql \ | ||
PATH=/home/pg_graphql/.cargo/bin:$PATH | ||
RUN chown postgres:postgres /home/pg_graphql | ||
USER postgres | ||
|
||
RUN \ | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain nightly && \ | ||
rustup --version && \ | ||
rustc --version && \ | ||
cargo --version | ||
|
||
# PGX | ||
RUN cargo install cargo-pgx | ||
|
||
RUN cargo pgx init --pg14 $(which pg_config) | ||
|
||
USER root | ||
|
||
COPY . . | ||
RUN cargo pgx install | ||
|
||
USER postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
create extension pg_graphql; | ||
|
||
create role anon; | ||
|
||
grant usage on schema public to anon; | ||
alter default privileges in schema public grant all on tables to anon; | ||
alter default privileges in schema public grant all on functions to anon; | ||
alter default privileges in schema public grant all on sequences to anon; | ||
|
||
grant usage on schema graphql to anon; | ||
grant all on function graphql.resolve to anon; | ||
|
||
alter default privileges in schema graphql grant all on tables to anon; | ||
alter default privileges in schema graphql grant all on functions to anon; | ||
alter default privileges in schema graphql grant all on sequences to anon; | ||
|
||
|
||
-- GraphQL Entrypoint | ||
create function graphql( | ||
"operationName" text default null, | ||
query text default null, | ||
variables jsonb default null, | ||
extensions jsonb default null | ||
) | ||
returns jsonb | ||
language sql | ||
as $$ | ||
select graphql.resolve( | ||
query := query, | ||
variables := coalesce(variables, '{}'), | ||
"operationName" := "operationName", | ||
extensions := extensions | ||
); | ||
$$; | ||
|
||
|
||
create table account( | ||
id serial primary key, | ||
email varchar(255) not null, | ||
created_at timestamp not null | ||
); | ||
|
||
|
||
create table blog( | ||
id serial primary key, | ||
owner_id integer not null references account(id) on delete cascade, | ||
name varchar(255) not null, | ||
description varchar(255), | ||
created_at timestamp not null | ||
); | ||
|
||
|
||
create type blog_post_status as enum ('PENDING', 'RELEASED'); | ||
|
||
|
||
create table blog_post( | ||
id uuid not null default gen_random_uuid() primary key, | ||
blog_id integer not null references blog(id) on delete cascade, | ||
title varchar(255) not null, | ||
body varchar(10000), | ||
status blog_post_status not null, | ||
created_at timestamp not null | ||
); | ||
|
||
|
||
-- 5 Accounts | ||
insert into public.account(email, created_at) | ||
values | ||
('[email protected]', now()), | ||
('[email protected]', now()), | ||
('[email protected]', now()), | ||
('[email protected]', now()), | ||
('[email protected]', now()); | ||
|
||
insert into blog(owner_id, name, description, created_at) | ||
values | ||
((select id from account where email ilike 'a%'), 'A: Blog 1', 'a desc1', now()), | ||
((select id from account where email ilike 'a%'), 'A: Blog 2', 'a desc2', now()), | ||
((select id from account where email ilike 'a%'), 'A: Blog 3', 'a desc3', now()), | ||
((select id from account where email ilike 'b%'), 'B: Blog 3', 'b desc1', now()); | ||
|
||
|
||
comment on schema public is '@graphql({"inflect_names": true})'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<html> | ||
<head> | ||
<title>GraphiQL - pg_graphql</title> | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/graphiql/2.0.4/graphiql.css" rel="stylesheet" /> | ||
</head> | ||
<body style="margin: 0;"> | ||
<div id="graphiql" style="height: 100vh;"></div> | ||
|
||
<script | ||
crossorigin | ||
src="https://unpkg.com/react/umd/react.production.min.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react-dom/umd/react-dom.production.min.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://cdnjs.cloudflare.com/ajax/libs/graphiql/2.0.4/graphiql.js" | ||
></script> | ||
<script> | ||
const fetcher = GraphiQL.createFetcher({ | ||
url: 'http://localhost:3001/rpc/graphql', | ||
}); | ||
ReactDOM.render( | ||
React.createElement(GraphiQL, { fetcher: fetcher }), | ||
document.getElementById('graphiql'), | ||
); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
comment = 'pg_graphql: GraphQL support' | ||
default_version = '@CARGO_VERSION@' | ||
module_pathname = '$libdir/rs_graphql' | ||
module_pathname = '$libdir/pg_graphql' | ||
relocatable = false | ||
superuser = false | ||
schema = 'graphql' |