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 11, 2024
1 parent cb2db57 commit fa8f030
Showing 1 changed file with 13 additions and 2 deletions.
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 fa8f030

Please sign in to comment.