Skip to content

Postgraphile v5 Support (#58)#66

Open
dargmuesli wants to merge 23 commits into
graphile:mainfrom
dargmuesli:fzy/v5/dargmuesli
Open

Postgraphile v5 Support (#58)#66
dargmuesli wants to merge 23 commits into
graphile:mainfrom
dargmuesli:fzy/v5/dargmuesli

Conversation

@dargmuesli
Copy link
Copy Markdown

Description

Further work on the v5 migration started by @FelixZY in #60.
Resolves #58

Performance impact

unknown

Security impact

unknown

Checklist

  • My code matches the project's code style and yarn lint:fix passes.
  • I've added tests for the new feature, and yarn test passes.
  • I have detailed the new feature in the relevant documentation.
  • I have added this feature to 'Pending' in the RELEASE_NOTES.md file (if one exists).
  • If this is a breaking change I've explained why.

FelixZY and others added 14 commits June 3, 2024 14:33
After bumping to the v5 package versions, tests would fail with the
following error:

```
● Test suite failed to run

  ReferenceError: TextEncoder is not defined

  > 1 | import * as pg from "pg";
      | ^
    2 |
    3 | export async function withPgPool<T = any>(
    4 |   cb: (pool: pg.Pool) => Promise<T>

    at Object.<anonymous> (node_modules/pg/lib/crypto/utils-webcrypto.js:22:21)
    at Object.<anonymous> (node_modules/pg/lib/crypto/utils.js:8:20)
    at Object.<anonymous> (node_modules/pg/lib/crypto/sasl.js:2:16)
    at Object.<anonymous> (node_modules/pg/lib/client.js:5:12)
    at Object.<anonymous> (node_modules/pg/lib/index.js:3:14)
    at Object.<anonymous> (__tests__/helpers.ts:1:1)
    at Object.<anonymous> (__tests__/schema.minimal_type.test.ts:2:1)
```

Based on [information from @SimenB](
  jsdom/jsdom#2524 (comment)
), it seems like you probably should not be using
`jest-environment-jsdom` to start with if you need access to
`TextEncoder` or `TextDecoder`.

Based on [this](
  https://stackoverflow.com/a/72369912/1137077
) answer on SO, I was able to verify that `@jest-environment node` at
the top of test files fixed the issue. However, it would seem more
logical to apply this as a global setting, given that postgraphile is
meant to run in a node context.

After setting `testEnvironment: jest-environment-node` in the global
config, I found that tests again started failing. However, the new
failures seem related to the v5 changes to plugins which is expected at
this stage.
The previous `moduleResolution: node` setting prevent importing types
from `graphile-build-pg/pg-introspection`.

`NodeNext` was chosen based on
https://github.com/graphile/crystal/blob/91e87ab6516490a4cc7b7fc6400efb7623fbd331/graphile-build/graphile-build/tsconfig.json#L9
This seems to be better in line with other v5 plugins and the new
`GraphileConfig.Preset` type.
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Feb 15, 2026

@socket-security
Copy link
Copy Markdown

socket-security Bot commented Feb 15, 2026

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm entities is 91.0% likely obfuscated

Confidence: 0.91

Location: Package overview

From: ?npm/postgraphile@5.0.0-rc.7npm/entities@4.5.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/entities@4.5.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm markdown-it is 91.0% likely obfuscated

Confidence: 0.91

Location: Package overview

From: ?npm/postgraphile@5.0.0-rc.7npm/markdown-it@14.1.1

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/markdown-it@14.1.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

Comment thread src/index.ts Outdated
Comment thread src/interfaces.ts Outdated
Comment on lines +18 to +21
pgGISTypeName,
pgGISSubtype,
pgGISHasZ,
pgGISHasM,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to make the field scope quite noisy, might be better to wrap these all up in a single attribute instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the types overall, please check again and let me know what you think

graphql: { GraphQLNonNull, GraphQLFloat },
inflection,
} = build;
const xFieldName = inflection.gisXFieldName(pgGISTypeName!);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally you want to provide more details to an inflector, so it has more choice as to what to call it. Passing just the type name is very limiting in choice, you can't for example attach smart tags or use the database schema from which it originates to make naming choices.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some refactoring on this, let me know if that went into a good direction

Comment thread src/PostgisRegisterTypesPlugin.ts Outdated
Comment thread src/PostgisRegisterTypesPlugin.ts Outdated
Comment on lines +93 to +94
(attribute.extensions as any).postgisTypeModifier =
pgAttribute.atttypmod;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm as yet undecided on the best way to handle type modifiers in V5.

Comment thread src/version.ts Outdated
@@ -1 +0,0 @@
export const version = "";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "postversion" script could be used to update the version to be used in each of the plugins; this would be helpful for consumers of the preset. Something like a scripts/postversion.mjs file:

#!/usr/bin/env node
import * as fs from "node:fs/promises";

const VERSION_TS = "src/vesion.ts";

const packageJsonString = await fs.readFile("package.json", "utf8");
const packageJson = JSON.parse(packageJsonString);

await fs.writeFile(
  VERSION_TS,
  `\
// This file is autogenerated by /scripts/postversion.mjs
export const version = ${JSON.stringify(packageJson.version)};
`,
);

and then add it to package.json:

npm pkg set scripts.postversion="node scripts/postversion.mjs"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently proposing to just include the version via an package (JSON) import. That way the version should always match the package version, at least after a release, I think. What would the benefit of the script be in contrast? 🙌

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advantage of the script version is that it means you don't need to import JSON, which makes the plugin compatible with a wider array of runtimes and tooling. Importing JSON has complexities in certain bundlers/etc and consumes more memory.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for sharing! I made the suggested change.

Comment thread src/index.ts
Comment thread README.md Outdated
```json
{
"extends": ["PostgisPreset"],
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { PostgisPreset } from "@graphile/postgis";

const preset: GraphileConfig.Preset = {
  extends: [
    // ... Amber/V4/etc presets
    PostgisPreset,
  ],
  // ...
};

export default preset;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Comment thread tsconfig.json Outdated
"noUnusedLocals": true,
"preserveWatchOutput": true
"preserveWatchOutput": true,
"resolveJsonModule": true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For importing the version from package.json it should be needed, I'd say. Let's discuss above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Copy Markdown
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a thorough review; but it's looking good! Try and minimize the difference with previous code as that makes review easier (and also eases migration for people who may have custom inflectors or other integrations/extensions). Thanks for your work on this!

@dargmuesli dargmuesli requested a review from benjie February 16, 2026 19:30
Copy link
Copy Markdown
Author

@dargmuesli dargmuesli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying out real world use of this at the moment. There are still things to discuss for sure that I'm not certain about yet. I was a (pure) consumer of these things before and just relied on them working, now this is me looking into their core which I always like to do when I have the time. Now there is the missing 20% or 10% maybe that I would spend very much time on compared to its result so maybe I should not do this. But I'd definitely collaborate on this further! If more brains share how to get this done, I'll keep this PR up to speed.

Comment thread __tests__/integration/__snapshots__/queries.test.ts.snap Outdated
@dargmuesli
Copy link
Copy Markdown
Author

@benjie I think this is ready for a full review now from my side, I have this running for some time in my dev setup now and outputs seem to fit!

@TBA-Lucas
Copy link
Copy Markdown

I tested the PR but I have issues with geometry(geometry, 4326) columns from Postgis returning "geom": null in postgraphile v5.

I only get GeometryGeometry as subtype, it seems that the plugin is currently unable to infer the specific subtype like GeometryPoint. Since our postgraphile v4 server is doing that just fine with the same database, I assume that due to migrating it from postgraphile v4 to v5 the PostGIS plugin is now stricter about how it decides geometry subtypes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Postgraphile V5 Support

4 participants