Skip to content

Commit

Permalink
fix: subscriptions payloads _entity w/ camelCase fileds
Browse files Browse the repository at this point in the history
  • Loading branch information
IcanDivideBy0 committed Dec 12, 2024
1 parent cb2db57 commit 4a6ccd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/query/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ 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)

## [2.19.0] - 2024-12-11
### Added
- Support for ordering with fulltext search (#2623)
Expand Down
15 changes: 13 additions & 2 deletions packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import {hashName} from '@subql/utils';
import {PgIntrospectionResultsByKind} from '@subql/x-graphile-build-pg';
import {makeExtendSchemaPlugin, gql, embed} from 'graphile-utils';
import {makeExtendSchemaPlugin, gql, embed, Resolvers} from 'graphile-utils';
import {DocumentNode} from 'graphql';

const filter = (event, args) => {
Expand Down Expand Up @@ -42,7 +42,7 @@ export const PgSubscriptionPlugin = makeExtendSchemaPlugin((build) => {
`,
];

const resolvers: Record<string, any> = {};
const resolvers: Resolvers = {};

// Generate subscription fields for all database tables
(pgIntrospectionResultsByKind as PgIntrospectionResultsByKind).class.forEach((table) => {
Expand All @@ -65,6 +65,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);
},
},
};
});

return {
Expand Down

0 comments on commit 4a6ccd7

Please sign in to comment.