Skip to content

Commit 5fd6f50

Browse files
committed
fix(send-email-link): use 'where' filter instead of 'condition'
The previous fix (#38) switched from singular-by-PK lookups to plural connections with the built-in postgraphile `condition:` argument. That works on a stock postgraphile server, but not on constructive: ConstructivePreset (constructive/graphile/graphile-settings/src/presets/constructive-preset.ts) explicitly disables PgConditionArgumentPlugin and PgConditionCustomFieldsPlugin, replacing `condition:` with the more powerful `where:` filter provided by graphile-connection-filter. Calling the queries against a real constructive server returns: Unknown argument "condition" on field "Query.databases". Unknown argument "condition" on field "Site.siteModules". status: 400 Switch all `condition:` arguments to the equivalent `where: { field: { equalTo: value } }` form. This matches the older in-monorepo implementation in constructive/functions/send-email-link/src/index.ts on the constructive repo, which has been running against this server config in production. This wasn't caught by the existing tests because the GraphQL clients are mocked with jest.fn().mockResolvedValue(...). The queries had never been validated against a real schema.
1 parent 4acf8e3 commit 5fd6f50

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

functions/send-email-link/handler.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import { send as sendPostmaster } from '@constructive-io/postmaster';
66
import { send as sendSmtp } from 'simple-smtp-server';
77
import { parseEnvBoolean } from '@pgpmjs/env';
88

9-
// Use plural connections with `condition` filter rather than singular-by-PK
10-
// (`user(id:)`, `database(id:)`). The constructive server's preset extends
11-
// NoUniqueLookupPreset, which deliberately disables singular root-field
12-
// lookups by unique constraint (including primary key) to keep the API
13-
// surface small. The plural+condition form is the supported way to fetch
14-
// a row by id.
9+
// Use plural connections with the `where` filter (graphile-connection-filter)
10+
// rather than `condition:` or singular-by-PK. The constructive server's
11+
// ConstructivePreset:
12+
// 1. Extends NoUniqueLookupPreset — disables singular root-field lookups
13+
// by unique constraint, including primary key (`database(id:)`,
14+
// `user(id:)`).
15+
// 2. Disables `PgConditionArgumentPlugin` — removes the built-in
16+
// `condition:` argument on connections.
17+
// The supported pattern is `where: { field: { equalTo: var } }`.
1518
const GetUser = gql`
1619
query GetUser($userId: UUID!) {
17-
users(condition: { id: $userId }, first: 1) {
20+
users(where: { id: { equalTo: $userId } }, first: 1) {
1821
nodes {
1922
username
2023
displayName
@@ -26,7 +29,7 @@ const GetUser = gql`
2629

2730
const GetDatabaseInfo = gql`
2831
query GetDatabaseInfo($databaseId: UUID!) {
29-
databases(condition: { id: $databaseId }, first: 1) {
32+
databases(where: { id: { equalTo: $databaseId } }, first: 1) {
3033
nodes {
3134
sites {
3235
nodes {
@@ -43,7 +46,7 @@ const GetDatabaseInfo = gql`
4346
theme
4447
}
4548
}
46-
siteModules(condition: { name: "legal_terms_module" }) {
49+
siteModules(where: { name: { equalTo: "legal_terms_module" } }) {
4750
nodes {
4851
data
4952
}

0 commit comments

Comments
 (0)