Skip to content

Commit 7f0225e

Browse files
authored
fix(live): live collection for single backward relation record (#625)
1 parent 4ef1b7b commit 7f0225e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

packages/graphile-build-pg/src/plugins/PgBackwardRelationPlugin.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ export default (function PgBackwardRelationPlugin(
174174
table.primaryKeyConstraint
175175
) {
176176
innerQueryBuilder.selectIdentifiers(table);
177+
innerQueryBuilder.makeLiveCollection(table);
178+
innerQueryBuilder.addLiveCondition(
179+
data => record => {
180+
return keys.every(
181+
key =>
182+
record[key.name] === data[key.name]
183+
);
184+
},
185+
keys.reduce((memo, key, i) => {
186+
memo[
187+
key.name
188+
] = sql.fragment`${foreignTableAlias}.${sql.identifier(
189+
foreignKeys[i].name
190+
)}`;
191+
return memo;
192+
}, {})
193+
);
177194
}
178195
keys.forEach((key, i) => {
179196
innerQueryBuilder.where(
@@ -207,6 +224,24 @@ export default (function PgBackwardRelationPlugin(
207224
const liveRecord =
208225
resolveInfo.rootValue &&
209226
resolveInfo.rootValue.liveRecord;
227+
const liveCollection =
228+
resolveInfo.rootValue &&
229+
resolveInfo.rootValue.liveCollection;
230+
const liveConditions =
231+
resolveInfo.rootValue &&
232+
resolveInfo.rootValue.liveConditions;
233+
if (
234+
subscriptions &&
235+
liveCollection &&
236+
liveConditions &&
237+
data.__live
238+
) {
239+
const { __id, ...rest } = data.__live;
240+
const condition = liveConditions[__id];
241+
const checker = condition(rest);
242+
243+
liveCollection("pg", table, checker);
244+
}
210245
if (record && liveRecord) {
211246
liveRecord("pg", table, record.__identifiers);
212247
}

0 commit comments

Comments
 (0)