From 4a6ccd71e5838a4cc0125984685be910559b6f52 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 --- packages/query/CHANGELOG.md | 3 +++ .../src/graphql/plugins/PgSubscriptionPlugin.ts | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/query/CHANGELOG.md b/packages/query/CHANGELOG.md index 25e7d2a24c..e444509c87 100644 --- a/packages/query/CHANGELOG.md +++ b/packages/query/CHANGELOG.md @@ -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) 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 {