Skip to content

Commit 4acf8e3

Browse files
authored
Merge pull request #38 from constructive-io/fix/queries-use-plural-with-filter
fix(send-email-link): use plural connections with condition filter
2 parents 9fb9705 + 392a846 commit 4acf8e3

2 files changed

Lines changed: 38 additions & 23 deletions

File tree

.github/workflows/test-k8s-deployment.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ jobs:
139139
kubectl wait --for=condition=complete job/constructive-db \
140140
-n constructive-functions --timeout=180s
141141
142+
- name: Restart job service after DB ready
143+
run: |
144+
kubectl rollout restart deploy/knative-job-service -n constructive-functions
145+
kubectl rollout status deploy/knative-job-service -n constructive-functions --timeout=120s
146+
142147
- name: Port-forward postgres and run e2e tests
143148
env:
144149
PGHOST: localhost

functions/send-email-link/handler.ts

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,47 @@ 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.
915
const GetUser = gql`
1016
query GetUser($userId: UUID!) {
11-
user(id: $userId) {
12-
username
13-
displayName
14-
profilePicture
17+
users(condition: { id: $userId }, first: 1) {
18+
nodes {
19+
username
20+
displayName
21+
profilePicture
22+
}
1523
}
1624
}
1725
`;
1826

1927
const GetDatabaseInfo = gql`
2028
query GetDatabaseInfo($databaseId: UUID!) {
21-
database(id: $databaseId) {
22-
sites {
23-
nodes {
24-
domains {
25-
nodes {
26-
subdomain
27-
domain
29+
databases(condition: { id: $databaseId }, first: 1) {
30+
nodes {
31+
sites {
32+
nodes {
33+
domains {
34+
nodes {
35+
subdomain
36+
domain
37+
}
2838
}
29-
}
30-
logo
31-
title
32-
siteThemes {
33-
nodes {
34-
theme
39+
logo
40+
title
41+
siteThemes {
42+
nodes {
43+
theme
44+
}
3545
}
36-
}
37-
siteModules(condition: { name: "legal_terms_module" }) {
38-
nodes {
39-
data
46+
siteModules(condition: { name: "legal_terms_module" }) {
47+
nodes {
48+
data
49+
}
4050
}
4151
}
4252
}
@@ -111,7 +121,7 @@ const sendEmailLink = async (
111121
databaseId
112122
});
113123

114-
const site = databaseInfo?.database?.sites?.nodes?.[0];
124+
const site = databaseInfo?.databases?.nodes?.[0]?.sites?.nodes?.[0];
115125
if (!site) {
116126
throw new Error('Site not found for database');
117127
}
@@ -177,7 +187,7 @@ const sendEmailLink = async (
177187
const inviter = await client.request<any>(GetUser, {
178188
userId: params.sender_id
179189
});
180-
inviterName = inviter?.user?.displayName;
190+
inviterName = inviter?.users?.nodes?.[0]?.displayName;
181191

182192
if (inviterName) {
183193
subject = `${inviterName} invited you to ${nick}!`;

0 commit comments

Comments
 (0)