Skip to content

Commit

Permalink
fix: load subscriptions relations
Browse files Browse the repository at this point in the history
  • Loading branch information
IcanDivideBy0 committed Dec 12, 2024
1 parent 4a6ccd7 commit 17e2381
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/query/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Fixed
- Subscriptions `_entity` field now includes camel cased properties (#2626)
- Subscriptions `_entity` field now returns all properties (#2626)

## [2.19.0] - 2024-12-11
### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/graphql/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class GraphqlModule implements OnModuleInit, OnModuleDestroy {
path: WS_ROUTE,
});

this.wsCleanup = useServer({schema}, wsServer);
this.wsCleanup = useServer({schema, context: {pgClient: this.pgPool}}, wsServer);
}

app.use(PinoLogger(PinoConfig));
Expand Down
18 changes: 12 additions & 6 deletions packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function makePayload(entityType: string): {type: DocumentNode; name: string} {
}

export const PgSubscriptionPlugin = makeExtendSchemaPlugin((build) => {
const {inflection, pgIntrospectionResultsByKind} = build;
const {inflection, pgIntrospectionResultsByKind, pgSql: sql} = build;

const typeDefs = [
gql`
Expand Down Expand Up @@ -68,11 +68,17 @@ export const PgSubscriptionPlugin = makeExtendSchemaPlugin((build) => {

resolvers[payloadName] = {
_entity: {
resolve: ({_entity}) => {
return Object.entries(_entity).reduce((acc, [key, value]) => {
const attr = table.attributes.find((attr) => attr.name === key);
return Object.assign(acc, {[inflection.column(attr)]: value});
}, _entity);
resolve: async ({id}, args, context, resolveInfo) => {
const [row] = await resolveInfo.graphile.selectGraphQLResultFromTable(
sql.identifier(table.namespace.name, table.name),
(tableAlias, queryBuilder) => {
queryBuilder.context.args = {blockHeight: sql.fragment`'999999999999999999'::bigint`};
queryBuilder.where(sql.fragment`${tableAlias}.id = ${sql.value(id)}`);
queryBuilder.limit(1);
}
);

return row;
},
},
};
Expand Down

0 comments on commit 17e2381

Please sign in to comment.