From fa8f0308f8761601fa2204fea2533c31886d00b0 Mon Sep 17 00:00:00 2001 From: Samuel Hurel Date: Wed, 11 Dec 2024 10:28:28 +0100 Subject: [PATCH] fix: subscriptions payloads _entity w/ camelCase fileds --- .../src/graphql/plugins/PgSubscriptionPlugin.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts b/packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts index 8a4b93e796..19550720b0 100644 --- a/packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts +++ b/packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts @@ -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) => { @@ -42,7 +42,7 @@ export const PgSubscriptionPlugin = makeExtendSchemaPlugin((build) => { `, ]; - const resolvers: Record = {}; + const resolvers: Resolvers = {}; // Generate subscription fields for all database tables (pgIntrospectionResultsByKind as PgIntrospectionResultsByKind).class.forEach((table) => { @@ -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 {