Skip to content

Commit

Permalink
fix(core): Support new object ref returned from plugin configuration fn
Browse files Browse the repository at this point in the history
Fixes #2906
  • Loading branch information
michaelbromley committed Jun 17, 2024
1 parent b393538 commit 45df738
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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 {}
13 changes: 13 additions & 0 deletions packages/core/e2e/plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -30,6 +31,7 @@ describe('Plugins', () => {
TestLazyExtensionPlugin,
TestRestPlugin,
PluginWithGlobalProviders,
WithNewConfigObjectReferencePlugin,
],
});

Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ async function runPluginConfigurations(config: RuntimeVendureConfig): Promise<Ru
for (const plugin of config.plugins) {
const configFn = getConfigurationFunction(plugin);
if (typeof configFn === 'function') {
config = await configFn(config);
const result = await configFn(config);
Object.assign(config, result);
}
}
return config;
Expand Down

0 comments on commit 45df738

Please sign in to comment.