Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning a new config object from a plugin's configuration function breaks #2906

Closed
michaelbromley opened this issue Jun 17, 2024 · 0 comments
Labels
type: bug 🐛 Something isn't working @vendure/core

Comments

@michaelbromley
Copy link
Member

Describe the bug
In Discord we had the report that the following config in a plugin resulted in the defined custom fields not getting registered as expected and not showing up in the GraphQL API:

@VendurePlugin({
  configuration: (config) => getCustomerConfig(config),
  // ... rest omitted for brevity
})
export class DCustomerPlugin {}

export const getCustomerConfig = (config: RuntimeVendureConfig): RuntimeVendureConfig => ({
  ...config,
  customFields: {
    ...config.customFields,
    Customer: [...config.customFields.Customer, ...customerCustomFields],
    User: [...config.customFields.User, ...userCustomFields],
  },
})

Here we can see that the getCustomerConfig is returning a new object instance, rather than mutating the config object that was passed into the function.

To Reproduce
Here's a minimal reproduction:

@VendurePlugin({
    configuration: config => {
         return {
            ...config,
            customFields: {
                ...config.customFields,
                Customer: [
                    {
                        name: 'testField',
                        type: 'string',
                    },
                ],
            },
        };
    },
})
class MyPlugin {}

It looks like the underlying reason for this is that internally, the ConfigService is calling the getConfig method in its constructor. This getConfig method is using an internal shared config object named activeConfig. Inside the core, it is expected that this object reference to activeConfig is used throughout the app. However, returning a new object instance in the example above breaks this assumption.

The solution can be to take the result returned by the plugin configuration function, and then merge it into the existing object reference.

Expected behavior
The above pattern should be supported, otherwise we are leaking out internal implementation details in a hard-to-understand-and-debug manner.

Environment (please complete the following information):

  • @vendure/core version: 2.2.5
  • Nodejs version: any
  • Database (mysql/postgres etc): any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working @vendure/core
Projects
None yet
Development

No branches or pull requests

1 participant