From 45df738eb2fa50f0d2028591e67fe9917b3b89bc Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Mon, 17 Jun 2024 15:49:00 +0200 Subject: [PATCH] fix(core): Support new object ref returned from plugin configuration fn Fixes #2906 --- .../with-new-config-object-reference.ts | 23 +++++++++++++++++++ packages/core/e2e/plugin.e2e-spec.ts | 13 +++++++++++ packages/core/src/bootstrap.ts | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 packages/core/e2e/fixtures/test-plugins/with-new-config-object-reference.ts diff --git a/packages/core/e2e/fixtures/test-plugins/with-new-config-object-reference.ts b/packages/core/e2e/fixtures/test-plugins/with-new-config-object-reference.ts new file mode 100644 index 0000000000..67cb41b846 --- /dev/null +++ b/packages/core/e2e/fixtures/test-plugins/with-new-config-object-reference.ts @@ -0,0 +1,23 @@ +import { Query, Resolver } from '@nestjs/graphql'; +import { VendurePlugin } from '@vendure/core'; + +/** + * https://github.com/vendure-ecommerce/vendure/issues/2906 + */ +@VendurePlugin({ + configuration: config => { + return { + ...config, + customFields: { + ...config.customFields, + Customer: [ + { + name: 'testField', + type: 'string', + }, + ], + }, + }; + }, +}) +export class WithNewConfigObjectReferencePlugin {} diff --git a/packages/core/e2e/plugin.e2e-spec.ts b/packages/core/e2e/plugin.e2e-spec.ts index 22a3f14de5..843ef4c49a 100644 --- a/packages/core/e2e/plugin.e2e-spec.ts +++ b/packages/core/e2e/plugin.e2e-spec.ts @@ -14,6 +14,7 @@ import { TestAPIExtensionPlugin } from './fixtures/test-plugins/with-api-extensi import { TestPluginWithConfig } from './fixtures/test-plugins/with-config'; import { PluginWithGlobalProviders } from './fixtures/test-plugins/with-global-providers'; import { TestLazyExtensionPlugin } from './fixtures/test-plugins/with-lazy-api-extensions'; +import { WithNewConfigObjectReferencePlugin } from './fixtures/test-plugins/with-new-config-object-reference'; import { TestPluginWithProvider } from './fixtures/test-plugins/with-provider'; import { TestRestPlugin } from './fixtures/test-plugins/with-rest-controller'; @@ -30,6 +31,7 @@ describe('Plugins', () => { TestLazyExtensionPlugin, TestRestPlugin, PluginWithGlobalProviders, + WithNewConfigObjectReferencePlugin, ], }); @@ -52,6 +54,17 @@ describe('Plugins', () => { expect(configService.defaultLanguageCode).toBe(LanguageCode.zh); }); + // https://github.com/vendure-ecommerce/vendure/issues/2906 + it('handles plugins that return new config object references', async () => { + const configService = server.app.get(ConfigService); + expect(configService.customFields.Customer).toEqual([ + { + name: 'testField', + type: 'string', + }, + ]); + }); + it('extends the admin API', async () => { const result = await adminClient.query(gql` query { diff --git a/packages/core/src/bootstrap.ts b/packages/core/src/bootstrap.ts index b687c0df9c..d55860ddd8 100644 --- a/packages/core/src/bootstrap.ts +++ b/packages/core/src/bootstrap.ts @@ -267,7 +267,8 @@ async function runPluginConfigurations(config: RuntimeVendureConfig): Promise