-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Next.js Grafserv package and create an example PostGraphile se…
…rver (#17)
- Loading branch information
Showing
43 changed files
with
3,252 additions
and
371 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 |
---|---|---|
|
@@ -24,11 +24,18 @@ jobs: | |
uses: actions/[email protected] | ||
with: | ||
fetch-depth: 2 | ||
- name: Install Poetry | ||
run: pipx install poetry | ||
- name: Setup Node.js | ||
uses: actions/[email protected] | ||
with: | ||
cache: yarn | ||
node-version-file: .node-version | ||
- name: Setup Python | ||
uses: actions/[email protected] | ||
with: | ||
cache: poetry | ||
python-version-file: .python-version | ||
- name: Install Node.js dependencies | ||
run: yarn install --immutable | ||
- name: Build | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
3.11 |
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,37 @@ | ||
[sqlfluff] | ||
dialect = postgres | ||
max_line_length = 120 | ||
templater = placeholder | ||
|
||
[sqlfluff:templater:placeholder] | ||
DATABASE_OWNER=owner_role | ||
param_style = colon | ||
|
||
[sqlfluff:rules:ambiguous.column_references] | ||
group_by_and_order_by_style = explicit | ||
|
||
[sqlfluff:rules:ambiguous.join] | ||
fully_qualify_join_types = both | ||
|
||
[sqlfluff:rules:capitalisation.functions] | ||
capitalisation_policy = lower | ||
extended_capitalisation_policy = lower | ||
|
||
[sqlfluff:rules:capitalisation.identifiers] | ||
capitalisation_policy = lower | ||
extended_capitalisation_policy = lower | ||
|
||
[sqlfluff:rules:capitalisation.literals] | ||
capitalisation_policy = upper | ||
|
||
[sqlfluff:rules:capitalisation.keywords] | ||
capitalisation_policy = upper | ||
|
||
[sqlfluff:rules:capitalisation.types] | ||
extended_capitalisation_policy = lower | ||
|
||
[sqlfluff:rules:convention.casting_style] | ||
preferred_type_casting_style = shorthand | ||
|
||
[sqlfluff:rules:references.consistent] | ||
single_table_references = unqualified |
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,2 @@ | ||
**/committed/*.sql | ||
schema.sql |
Large diffs are not rendered by default.
Oops, something went wrong.
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,9 @@ | ||
/* eslint-disable */ | ||
//prettier-ignore | ||
module.exports = { | ||
name: "@yarnpkg/plugin-after-install", | ||
factory: function (require) { | ||
"use strict";var plugin=(()=>{var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var r=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(o,e)=>(typeof require<"u"?require:o)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var I=(t,o)=>{for(var e in o)s(t,e,{get:o[e],enumerable:!0})},h=(t,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of x(o))!C.call(t,n)&&n!==e&&s(t,n,{get:()=>o[n],enumerable:!(a=g(o,n))||a.enumerable});return t};var k=t=>h(s({},"__esModule",{value:!0}),t);var P={};I(P,{default:()=>y});var d=r("@yarnpkg/core");var f=r("@yarnpkg/core"),c={afterInstall:{description:"Hook that will always run after install",type:f.SettingsType.STRING,default:""}};var p=r("clipanion"),u=r("@yarnpkg/core");var m=r("@yarnpkg/shell"),l=async(t,o)=>{let e=t.get("afterInstall"),a=!!t.projectCwd?.endsWith(`dlx-${process.pid}`);return e&&!a?(o&&console.log("Running `afterInstall` hook..."),(0,m.execute)(e,[],{cwd:t.projectCwd||void 0})):0};var i=class extends p.Command{async execute(){let o=await u.Configuration.find(this.context.cwd,this.context.plugins);return l(o,!1)}};i.paths=[["after-install"]];var w={configuration:c,commands:[i],hooks:{afterAllInstalled:async(t,o)=>{if(o?.mode===d.InstallMode.UpdateLockfile)return;if(await l(t.configuration,!0))throw new Error("The `afterInstall` hook failed, see output above.")}}},y=w;return k(P);})(); | ||
return plugin; | ||
} | ||
}; |
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,9 +1,10 @@ | ||
afterInstall: yarn workspaces foreach -A run postinstall | ||
compressionLevel: mixed | ||
|
||
enableGlobalCache: false | ||
|
||
nodeLinker: node-modules | ||
|
||
npmPublishAccess: public | ||
|
||
plugins: | ||
- checksum: 0a2a35fbed2f33f0df1ceb1db51bf72554201f994eaecb86cbc62a295c3d05f7cc44fa8be8e64fc5e1c0bee4f529a17a0cc429ea9e3486ad467443291d5a8e3b | ||
path: .yarn/plugins/@yarnpkg/plugin-after-install.cjs | ||
spec: "https://raw.githubusercontent.com/mhassan1/yarn-plugin-after-install/v0.6.0/bundles/@yarnpkg/plugin-after-install.js" | ||
yarnPath: .yarn/releases/yarn-4.2.2.cjs |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
POSTGRES_URL=postgresql://postgres:postgres@localhost:5432/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 @@ | ||
GRAPHILE_ENV=development |
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,3 @@ | ||
*.tsbuildinfo | ||
.next | ||
node_modules |
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,6 @@ | ||
const graphileMigrateConfig = { | ||
connectionString: "postgresql://postgres:postgres@localhost:5432/postgres", | ||
migrationsFolder: "src/migrations", | ||
}; | ||
|
||
module.exports = graphileMigrateConfig; |
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,2 @@ | ||
node_modules | ||
schema.graphql |
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,9 @@ | ||
assume_in_transaction = true | ||
excluded_rules = [ | ||
"ban-drop-table", | ||
"prefer-big-int", | ||
"prefer-bigint-over-smallint", | ||
"require-concurrent-index-creation", | ||
"require-concurrent-index-deletion", | ||
] | ||
pg_version = "16.0" |
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,17 @@ | ||
# @spear-ai/example-postgraphile-server | ||
|
||
An example [PostGraphile](https://postgraphile.org) server to test against custom plugins. | ||
|
||
## Installation | ||
|
||
```shell | ||
yarn install | ||
``` | ||
|
||
## Usage | ||
|
||
Run the PostGraphile server in dev mode: | ||
|
||
```shell | ||
yarn turbo run dev | ||
``` |
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,18 @@ | ||
name: forerunner-database | ||
services: | ||
postgresql: | ||
container_name: postgraphile-postgresql | ||
environment: | ||
PGHOST: /var/run/postgresql | ||
POSTGRES_DB: postgres | ||
POSTGRES_HOST: /var/run/postgresql | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_USER: postgres | ||
healthcheck: | ||
interval: 3s | ||
retries: 10 | ||
test: pg_isready -h postgresql -U postgres -d postgres | ||
timeout: 3s | ||
image: supabase/postgres:15.1.1.52 | ||
ports: | ||
- 5432:5432 |
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,12 @@ | ||
import { baseEslintConfig, prettierConfig } from "@spear-ai/eslint-config"; | ||
|
||
/** @type {import("eslint").Linter.FlatConfig} */ | ||
const eslintConfig = [ | ||
{ | ||
ignores: ["**/.next", "dist", "node_modules"], | ||
}, | ||
...baseEslintConfig, | ||
prettierConfig, | ||
]; | ||
|
||
export default eslintConfig; |
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,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
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,23 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
experimental: { | ||
esmExternals: true, | ||
serverComponentsExternalPackages: [ | ||
"grafast", | ||
"grafserv", | ||
"graphile-export", | ||
"graphql", | ||
"postgraphile", | ||
"ruru", | ||
], | ||
}, | ||
poweredByHeader: false, | ||
typescript: { | ||
ignoreBuildErrors: true, | ||
}, | ||
}; | ||
|
||
export default nextConfig; |
11 changes: 11 additions & 0 deletions
11
packages/example-postgraphile-server/npmpackagejsonlint.config.cjs
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,11 @@ | ||
module.exports = { | ||
extends: ["@spear-ai/npm-package-json-lint-config/spear-application"], | ||
rules: { | ||
"prefer-absolute-version-dependencies": [ | ||
"error", | ||
{ | ||
exceptions: ["@spear-ai/grafserv-next-server", "@spear-ai/graphile-sort-schema-plugin"], | ||
}, | ||
], | ||
}, | ||
}; |
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,70 @@ | ||
{ | ||
"name": "@spear-ai/example-postgraphile-server", | ||
"version": "1.0.0", | ||
"description": "Example PostGraphile server", | ||
"author": { | ||
"name": "Spear AI", | ||
"email": "[email protected]", | ||
"url": "https://spear.ai" | ||
}, | ||
"type": "module", | ||
"dependencies": { | ||
"@dataplan/pg": "0.0.1-beta.22", | ||
"@graphile/simplify-inflection": "8.0.0-beta.5", | ||
"@spear-ai/grafserv-next-server": "*", | ||
"@spear-ai/graphile-sort-schema-plugin": "*", | ||
"dirfilename": "1.1.1", | ||
"next": "14.2.3", | ||
"postgraphile": "5.0.0-beta.25", | ||
"react": "18.3.1", | ||
"react-dom": "18.3.1", | ||
"ruru": "patch:ruru@npm%3A2.0.0-beta.12#~/.yarn/patches/ruru-npm-2.0.0-beta.12-299bc077af.patch" | ||
}, | ||
"devDependencies": { | ||
"@dotenv-run/cli": "1.3.5", | ||
"@spear-ai/eslint-config": "20.0.0", | ||
"@spear-ai/npm-package-json-lint-config": "3.1.1", | ||
"@spear-ai/prettier-config": "2.2.0", | ||
"@spear-ai/tsconfig": "4.0.0", | ||
"autoprefixer": "10.4.19", | ||
"concurrently": "8.2.2", | ||
"eslint": "8.57.0", | ||
"graphile-migrate": "2.0.0-rc.2", | ||
"graphql": "16.8.1", | ||
"npm-package-json-lint": "7.1.0", | ||
"postcss": "8.4.38", | ||
"prettier": "3.2.5", | ||
"squawk-cli": "0.28.0", | ||
"tailwindcss": "3.4.3", | ||
"turbo": "1.13.3", | ||
"typescript": "5.4.5" | ||
}, | ||
"license": "MIT", | ||
"packageManager": "[email protected]", | ||
"private": true, | ||
"repository": { | ||
"type": "git", | ||
"directory": "packages/example-postgraphile-server", | ||
"url": "https://github.com/spear-ai/api.git" | ||
}, | ||
"scripts": { | ||
"build": "yarn run next:build", | ||
"database:pre-dev": "docker compose up --build --wait", | ||
"dev": "concurrently yarn:migrate:dev yarn:next:dev", | ||
"dotenv-linter:check": "docker run --rm -v \"$(pwd)\":/app -w /app dotenvlinter/dotenv-linter:3.3.0 .env*", | ||
"dotenv-linter:fix": "docker run --rm -v \"$(pwd)\":/app -w /app dotenvlinter/dotenv-linter:3.3.0 fix .env*", | ||
"eslint:check": "eslint --max-warnings 0 .", | ||
"eslint:fix": "yarn eslint:check --fix", | ||
"migrate:dev": "dotenv-run -e development -- graphile-migrate watch", | ||
"migrate:up": "dotenv-run -e production -- graphile-migrate watch --once", | ||
"next:build": "next build", | ||
"next:dev": "next dev", | ||
"next:start": "next start", | ||
"npmpkgjsonlint:check": "npmPkgJsonLint .", | ||
"pre-dev": "yarn database:pre-dev", | ||
"prettier:check": "prettier --check .", | ||
"prettier:fix": "prettier --write .", | ||
"squawk:check": "squawk --assume-in-transaction src/migrations/current/*.sql", | ||
"typescript:check": "tsc --noEmit" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/example-postgraphile-server/src/app/api/graphiql/route.ts
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,8 @@ | ||
import { NextResponse } from "next/server"; | ||
import { ruruHTML } from "ruru/server"; | ||
|
||
export const GET = () => | ||
new NextResponse(ruruHTML({ endpoint: `/api/graphql` }), { | ||
headers: { "Content-Type": "text/html" }, | ||
status: 200, | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/example-postgraphile-server/src/app/api/graphql/route.ts
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,38 @@ | ||
import path from "node:path"; | ||
import { PgSimplifyInflectionPreset } from "@graphile/simplify-inflection"; | ||
import { grafserv } from "@spear-ai/grafserv-next-server"; | ||
import { sortSchemaPlugin } from "@spear-ai/graphile-sort-schema-plugin"; | ||
import { dirname } from "dirfilename"; | ||
import { NextRequest } from "next/server"; | ||
import { makeSchema } from "postgraphile"; | ||
import { makePgService } from "postgraphile/adaptors/pg"; | ||
import { PostGraphileAmberPreset } from "postgraphile/presets/amber"; | ||
import { PostGraphileRelayPreset } from "postgraphile/presets/relay"; | ||
|
||
const preset: GraphileConfig.Preset = { | ||
extends: [PostGraphileAmberPreset, PostGraphileRelayPreset, PgSimplifyInflectionPreset], | ||
gather: { | ||
pgStrictFunctions: true, | ||
}, | ||
pgServices: [ | ||
makePgService({ | ||
connectionString: process.env.POSTGRES_URL ?? "", | ||
schemas: ["public"], | ||
}), | ||
], | ||
plugins: [sortSchemaPlugin], | ||
schema: { | ||
dontSwallowErrors: process.env.NODE_ENV === "production", | ||
exportSchemaSDLPath: path.join(dirname(import.meta.url), "./schema.graphql"), | ||
pgSimplifyPatch: false, | ||
retryOnInitFail: process.env.NODE_ENV === "development", | ||
sortExport: true, | ||
}, | ||
}; | ||
|
||
export const POST = async (request: NextRequest) => { | ||
const { schema } = await makeSchema(preset); | ||
const server = grafserv({ preset, schema }); | ||
const handle = server.createGraphQLHandler(); | ||
return handle(request); | ||
}; |
Oops, something went wrong.