Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce PgRegistry; codecs own relations; type overhaul #260

Merged
merged 192 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
192 commits
Select commit Hold shift + click to select a range
a6b60e9
Forbid duplicate source or codec names
benjie Mar 22, 2023
c16f618
Start thinking about PgCodecRelations
benjie Mar 23, 2023
542b01f
Massive rewriting of @dataplan/pg types
benjie Mar 23, 2023
c16534e
Remove unused interface
benjie Mar 24, 2023
d5f15a7
Add name to source generics
benjie Mar 24, 2023
fc29a46
I have a better idea. This is a nightmare.
benjie Mar 24, 2023
5bb8633
Progress?
benjie Mar 24, 2023
a31e12e
Simplify
benjie Mar 24, 2023
559113d
Remove stuff
benjie Mar 24, 2023
8db1d81
Basic validation of approach
benjie Mar 24, 2023
f99b400
Comment
benjie Mar 24, 2023
e3e53e7
A lot of exampleSchema rewriting
benjie Mar 27, 2023
b91b70e
enumCodec needs generic name
benjie Mar 27, 2023
cc4504c
Remove simplify to solve 'excessively deep and possibly infinite' TS …
benjie Mar 27, 2023
1f148d6
Back to one builder flow
benjie Mar 27, 2023
8c1addf
Nicer types
benjie Mar 27, 2023
a31fd60
Working towards having TypeScript pass
benjie Mar 27, 2023
4fae377
Fix TypeScript expansion
benjie Mar 28, 2023
d8b2564
Tmp
benjie Mar 28, 2023
273c6c1
TypeScript fix
benjie Mar 28, 2023
8422d2f
Update example script
benjie Mar 28, 2023
e1296a9
WIP
benjie Mar 28, 2023
2b3ba35
Introduce PgCodecRelationConfig to use during gather phase
benjie Mar 28, 2023
83f19a0
Moar work
benjie Mar 28, 2023
69876df
Watch me WIP
benjie Mar 28, 2023
1c45b1d
WIIIIIIIIP
benjie Mar 28, 2023
1ad66c2
1 error left...
benjie Mar 28, 2023
cf13333
Fix final TS errors
benjie Mar 28, 2023
3062791
Update references
benjie Mar 29, 2023
e8d097a
Fix @graphile/simplify-inflection plugin
benjie Mar 29, 2023
6c8c720
Fix graphile-utils
benjie Mar 29, 2023
52f1ea4
Update packages relating to jest/babel in the hopes Jest'll support '…
benjie Mar 29, 2023
a24ce91
Recursive codec adding, relational validation, fix adding relations
benjie Mar 29, 2023
b170733
Fix some bad remoteSource references
benjie Mar 29, 2023
3a9e2dd
refs is now optional, handle that
benjie Mar 29, 2023
6c26c4d
Fix some logic around refs
benjie Mar 29, 2023
ff8dd49
Update mermaid (why?)
benjie Mar 29, 2023
037a4a8
Use null prototype
benjie Mar 29, 2023
1157510
simpleCollections: both
benjie Mar 29, 2023
5ef6443
Overhaul pgProcedures hooks
benjie Mar 29, 2023
ca580db
Schema reordered
benjie Mar 29, 2023
638c2be
Lint fixes
benjie Mar 29, 2023
b7437f4
Update babel generator
benjie Mar 29, 2023
bf7fc5a
Freshen yarn.lock
benjie Mar 29, 2023
0ccc680
Manually dedupe estree
benjie Mar 29, 2023
2056b44
Add type assertion
benjie Mar 29, 2023
502f26f
Use 'yarn bin' to resolve path to executable
benjie Mar 29, 2023
d4d89a8
Fix all the exportAs's
benjie Mar 29, 2023
3a449e0
Fix exporting
benjie Mar 29, 2023
e443b8e
Fix more exports
benjie Mar 29, 2023
e61019e
Fix exportability, don't export introspection results
benjie Mar 29, 2023
bd056db
Fix pgSource building in export (get from registry)
benjie Mar 29, 2023
5213aef
Preset might not have a grafserv section
benjie Mar 29, 2023
e6b358c
Detect non-plain objects and throw an error indicating EXPORTABLE sho…
benjie Mar 29, 2023
a8ca161
Superuser can do anything
benjie Mar 29, 2023
a731237
Fix exporting and TypeScript issues
benjie Mar 29, 2023
51ff738
Lint
benjie Mar 29, 2023
1f2627b
Export each individual codec
benjie Mar 29, 2023
715b2bc
More helpful error
benjie Mar 29, 2023
9f49337
Fix codec exporting
benjie Mar 29, 2023
1755d5c
Simplified queries
benjie Mar 29, 2023
14c3e2b
Split PgPolymorphism gather function into two phases (yuck)
benjie Mar 29, 2023
e8056f0
Don't clone codecs; mutate them directly
benjie Mar 29, 2023
d425b34
Restore text cast for unknown reason
benjie Mar 29, 2023
969957d
Lint
benjie Mar 29, 2023
cf0090f
More exportable things
benjie Mar 29, 2023
03cff3e
PgSource -> PgResource
benjie Mar 30, 2023
930576d
Refactor helpers, fix resulting type errors
benjie Mar 30, 2023
77d3309
Reorder PgResource generics
benjie Mar 30, 2023
9ca17e9
Formatting
benjie Mar 30, 2023
12539da
Remove the 'main' function from PgIntrospectionPlugin
benjie Mar 30, 2023
ef08c24
PgTypeCodec -> PgCodec
benjie Mar 30, 2023
6785c42
Lint
benjie Mar 30, 2023
4f056c8
More Source -> Resource renaming
benjie Mar 30, 2023
6478144
More Source -> Resource renaming
benjie Mar 30, 2023
398c59d
More Source -> Resource renaming
benjie Mar 30, 2023
7e4107e
More Source -> Resource renaming
benjie Mar 30, 2023
6d60240
More Source -> Resource renaming
benjie Mar 30, 2023
ad22d9a
More Source -> Resource renaming
benjie Mar 30, 2023
85918aa
More Source -> Resource renaming
benjie Mar 30, 2023
81abc67
More Source -> Resource renaming
benjie Mar 30, 2023
343e9ec
More Source -> Resource renaming
benjie Mar 30, 2023
da9329d
Tweak
benjie Mar 30, 2023
98726af
This isn't actually used
benjie Mar 30, 2023
3954100
Pull in some fixes from other branch
benjie Mar 30, 2023
c4e12c1
sourceEvents isn't even used
benjie Mar 30, 2023
fe96918
Fix some comments
benjie Mar 30, 2023
117ba50
finalSource -> finalResource
benjie Mar 30, 2023
73c226e
More source->resource
benjie Mar 30, 2023
8b879a1
dataSource -> resource
benjie Mar 30, 2023
8feab4c
Lint fixes
benjie Mar 30, 2023
8110236
pgTypeSource->pgTypeResource
benjie Mar 30, 2023
8675d36
Rename more sources -> resources
benjie Mar 30, 2023
97160f5
Rename more source -> resource
benjie Mar 30, 2023
3d8d4f4
Yet more source->resource
benjie Mar 30, 2023
3854d5f
Lint fixes
benjie Mar 30, 2023
a004142
Yet more source->resource
benjie Mar 30, 2023
df7e8cd
PgTypeColumn* -> PgCodecAttribute*
benjie Mar 30, 2023
3d2356a
Lint
benjie Mar 30, 2023
cdc39ba
Refactor relationship inflectors to be codec-centric
benjie Mar 31, 2023
5900f44
PgEnumTypeCodec -> PgEnumCodec
benjie Mar 31, 2023
216a406
Lint
benjie Mar 31, 2023
c111971
More PgCodecAny updates
benjie Mar 31, 2023
c40b06b
Remove unnecessary explicit generic defaults
benjie Mar 31, 2023
c8a10c4
Default generics for PgResource
benjie Mar 31, 2023
6233037
More accepting generic helpers
benjie Mar 31, 2023
0318b57
More useful PgResourceAny
benjie Mar 31, 2023
c07cad6
Tighten up a type
benjie Mar 31, 2023
972dd8d
Incorrect name on domainOfCodec
benjie Mar 31, 2023
95e3feb
Reorder generic
benjie Mar 31, 2023
7d22f19
Add back relation validation
benjie Mar 31, 2023
76c84da
Allow specifying naked PgCodec
benjie Mar 31, 2023
e2ee7c9
No need for PgCodecAny anymore
benjie Mar 31, 2023
dddc4f9
Get rid of PgResourceParameterAny
benjie Mar 31, 2023
2cf6e3e
Reorder PgResourceOptions generic so name comes first like for PgReso…
benjie Mar 31, 2023
0c68c39
Lint fixes
benjie Mar 31, 2023
576694b
Export makeRegistry
benjie Mar 31, 2023
8c8dae9
Tweak more generics to allow simplification
benjie Mar 31, 2023
d20961e
Remove unused code
benjie Mar 31, 2023
45feb81
Reorder PgFunctionResourceOptions so name comes first
benjie Mar 31, 2023
9400af7
Use type helpers to simplify
benjie Mar 31, 2023
8bdeef0
Simplify more types
benjie Mar 31, 2023
805c503
More type helper usage
benjie Mar 31, 2023
d099108
More simplification
benjie Mar 31, 2023
62e9b4b
Revert and simplify
benjie Mar 31, 2023
3c873fa
Simplify types
benjie Mar 31, 2023
3510ffa
Simplify another type
benjie Mar 31, 2023
f23bfb8
Formatting
benjie Mar 31, 2023
c305474
Simplify more types
benjie Mar 31, 2023
a3b55be
Lint
benjie Mar 31, 2023
c840d16
Simplification
benjie Mar 31, 2023
00fd2ed
Simplify types in example schema
benjie Mar 31, 2023
6668632
Simplify
benjie Mar 31, 2023
836f491
Lint fix
benjie Mar 31, 2023
ae5b058
Fix some generics
benjie Mar 31, 2023
b646ed8
Simplify
benjie Mar 31, 2023
e0b3bf6
Tidy
benjie Apr 3, 2023
8491f73
Simplify
benjie Apr 3, 2023
a7c3299
Simplicity and consistency
benjie Apr 3, 2023
08e8555
Fix types during relationship navigation and add a 'test' for it
benjie Apr 3, 2023
cf31496
Simplify and fix PgCodec types
benjie Apr 3, 2023
5161d24
Tidying
benjie Apr 3, 2023
fd321dc
Simplify
benjie Apr 3, 2023
2175be2
Simplify generics
benjie Apr 3, 2023
5a4f662
User code shouldn't need ugly casts even if we need them internally i…
benjie Apr 3, 2023
8f3911a
Fix some PgCodec generics (and cascading issues)
benjie Apr 3, 2023
2bde87b
Refs are on codecs now; fix old types
benjie Apr 3, 2023
985b0bc
Remove pointless freeze
benjie Apr 3, 2023
92ed3c6
Simplify codec types in PgCodecsPlugin and fix the cascade
benjie Apr 3, 2023
a40d987
No realm
benjie Apr 3, 2023
9bc1391
_columnName takes the codec with the columns as argument
benjie Apr 3, 2023
88b20d1
Joins are between codecs that have columns
benjie Apr 3, 2023
6fb1d3f
More codec column enforcement
benjie Apr 3, 2023
0210a44
Another helper type, for lists
benjie Apr 3, 2023
22db5ab
Lint
benjie Apr 3, 2023
4d220ac
Don't try and run the type test
benjie Apr 3, 2023
2f775a2
More type simplification
benjie Apr 3, 2023
2786ac6
Correct type of enums
benjie Apr 3, 2023
a7f1db9
Lint for more exportables
benjie Apr 3, 2023
8f57d61
Fix outdated name
benjie Apr 3, 2023
38a9350
Split registry into its own plugin
benjie Apr 3, 2023
95eabbc
Lint fixes
benjie Apr 3, 2023
e14173d
Remove unused imports
benjie Apr 3, 2023
8221274
Remove need to pass <any> to PgSelect/PgSelectSingle
benjie Apr 3, 2023
10d0c33
Remove redundant <any> from ExecutableStep
benjie Apr 3, 2023
80c70c9
Remove more redundant <any>s
benjie Apr 3, 2023
5e1f63b
More precise type
benjie Apr 3, 2023
2e0788b
Remove more redundant <any>s
benjie Apr 3, 2023
0a03096
More type fixes
benjie Apr 3, 2023
e664168
Fix another codec generic
benjie Apr 3, 2023
a1ae185
Lint
benjie Apr 3, 2023
062f364
Remove more redundant <any>s
benjie Apr 3, 2023
4a2fb3b
Simplify more generics
benjie Apr 3, 2023
ef07282
Lint
benjie Apr 3, 2023
bd400f1
Tweak generics
benjie Apr 4, 2023
c7e8657
Simplify generics further
benjie Apr 4, 2023
7415333
Simplify more generics
benjie Apr 4, 2023
4c7fe95
Enable a naked PgResource by handling fallback in GetPgCodecColumns
benjie Apr 4, 2023
f811fa3
Get rid of PgResourceAny
benjie Apr 4, 2023
e6e4d81
Get rid of PgRegistryAny
benjie Apr 4, 2023
cccd6c3
Remove more <any>s
benjie Apr 4, 2023
5524a93
More tidying of generics
benjie Apr 4, 2023
f76fea4
Type fixes
benjie Apr 4, 2023
0a89b2e
More type fixes
benjie Apr 4, 2023
3f5cded
Fix more generics
benjie Apr 4, 2023
5a63bae
Remove more <any>s
benjie Apr 4, 2023
596ed33
Remove unnecessary casting
benjie Apr 4, 2023
7eae47f
Fix docs
benjie Apr 4, 2023
d5312e6
docs(changeset): TypeScript v5 is now required
benjie Apr 4, 2023
96b0bd1
docs(changeset): `PgSource` has been renamed to `PgResource`, `PgType…
benjie Apr 4, 2023
2e2f1f1
Remove unused type
benjie Apr 4, 2023
9d9e01e
Lint
benjie Apr 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .changeset/lemon-gifts-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
"@graphile/simplify-inflection": patch
"jest-serializer-graphql-schema": patch
"eslint-plugin-graphile-export": patch
"graphile-build-pg": patch
"graphile-build": patch
"graphile-utils": patch
"jest-serializer-simple": patch
"postgraphile": patch
"ruru-components": patch
"pg-introspection": patch
"@dataplan/json": patch
"graphile-config": patch
"graphile-export": patch
"@localrepo/postgraphile-website": patch
"@dataplan/pg": patch
"grafserv": patch
"grafast": patch
"@localrepo/grafast-website": patch
"tamedevil": patch
"graphile": patch
"pg-sql2": patch
"ruru": patch
"@graphile/lds": patch
"@graphile/lru": patch
---

TypeScript v5 is now required
49 changes: 49 additions & 0 deletions .changeset/odd-mayflies-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
"@graphile/simplify-inflection": patch
"graphile-build-pg": patch
"postgraphile": patch
"@dataplan/pg": patch
---

`PgSource` has been renamed to `PgResource`, `PgTypeCodec` to `PgCodec`,
`PgEnumTypeCodec` to `PgEnumCodec`, `PgTypeColumn` to `PgCodecAttribute` (and
similar for related types/interfaces). `source` has been replaced by `resource`
in various of the APIs where it relates to a `PgResource`.

`PgSourceBuilder` is no more, instead being replaced with `PgResourceOptions`
and being built into the final `PgResource` via the new
`makeRegistryBuilder`/`makeRegistry` functions.

`build.input` no longer contains the `pgSources` directly, instead
`build.input.pgRegistry.pgResources` should be used.

The new registry system also means that various of the hooks in the gather phase
have been renamed/replaced, there's a new `PgRegistryPlugin` plugin in the
default preset. The only plugin that uses the `main` method in the `gather`
phase is now `PgRegistryPlugin` - if you are using the `main` function for
Postgres-related behaviors you should consider moving your logic to hooks
instead.

Plugin ordering has changed and thus the shape of the final schema is likely to
change (please use `lexicographicSortSchema` on your before/after schemas when
comparing).

Relationships are now from a codec to a resource, rather than from resource to
resource, so all the relationship inflectors (`singleRelation`,
`singleRelationBackwards`, `_manyRelation`, `manyRelationConnection`,
`manyRelationList`) now accept different parameters
(`{registry, codec, relationName}` instead of `{source, relationaName}`).

Significant type overhaul, most generic types no longer require generics to be
explicitly passed in many circumstances. `PgSelectStep`, `PgSelectSingleStep`,
`PgInsertStep`, `PgUpdateStep` and `PgDeleteStep` now all accept the resource as
their single type parameter rather than accepting the 4 generics they did
previously. `PgClassExpressionStep` now accepts just a codec and a resource as
generics. `PgResource` and `PgCodec` have gained a new `TName extends string`
generic at the very front that is used by the registry system to massively
improve continuity of the types through all the various APIs.

Fixed various issues in schema exporting, and detect more potential
issues/oversights automatically.

Fixes an RBAC bug when using superuser role for introspection.
2 changes: 1 addition & 1 deletion grafast/dataplan-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
"devDependencies": {
"@types/jest": "^27.5.1",
"jest": "^28.1.0",
"jest": "^28.1.3",
"jest-serializer-simple": "workspace:^",
"typescript": "^5.0.0-beta"
}
Expand Down
9 changes: 2 additions & 7 deletions grafast/dataplan-json/src/steps/jsonParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
GrafastResultsList,
GrafastValuesList,
} from "grafast";
import { access, ExecutableStep } from "grafast";
import { access, ExecutableStep, exportAs } from "grafast";

export type JSONValue =
| string
Expand Down Expand Up @@ -85,9 +85,4 @@ export function jsonParse<TJSON extends JSONValue>(
return new JSONParseStep<TJSON>($string);
}

Object.defineProperty(jsonParse, "$$export", {
value: {
moduleName: "@dataplan/json",
exportName: "jsonParse",
},
});
exportAs("@dataplan/json", jsonParse, "jsonParse");
2 changes: 1 addition & 1 deletion grafast/dataplan-pg/__tests__/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const schema = makeExampleSchema();
+--------------------------------------------------------------------------+*/

/*
class ConnectionStep<TSubplan extends ExecutableStep<any>> extends ExecutableStep<Opaque<any>> {
class ConnectionStep<TSubplan extends ExecutableStep> extends ExecutableStep<Opaque<any>> {
constructor(public readonly subplan: TSubplan) {
super();
}
Expand Down
2 changes: 1 addition & 1 deletion grafast/dataplan-pg/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export async function runTestQuery(
const document = parse(source);

const operationAST = getOperationAST(document, undefined);
const operationType = operationAST.operation;
const operationType = operationAST!.operation;

const validationErrors = validate(schema, document);
if (validationErrors.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion grafast/dataplan-pg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"graphile-export": "workspace:*",
"graphql": "16.1.0-experimental-stream-defer.6",
"iterall": "^1.3.0",
"jest": "^28.1.0",
"jest": "^28.1.3",
"jest-serializer-simple": "workspace:^",
"json5": "^2.2.0",
"license-checker-webpack-plugin": "^0.2.1",
Expand Down
Loading