Skip to content

Commit

Permalink
Introduce PgRegistry; codecs own relations; type overhaul (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Apr 4, 2023
2 parents 6ef8e77 + 9d9e01e commit 4ab5ca5
Show file tree
Hide file tree
Showing 142 changed files with 18,204 additions and 19,435 deletions.
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

0 comments on commit 4ab5ca5

Please sign in to comment.