From 2a68e784e348cb67240b4943bc9cffb26b571c87 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 2 Mar 2021 12:54:54 +0100 Subject: [PATCH] Fix race condition between Inject and Injectable (#1589) --- packages/graphql-modules/src/di/decorators.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/graphql-modules/src/di/decorators.ts b/packages/graphql-modules/src/di/decorators.ts index ae9080f579..ca23ed43d0 100644 --- a/packages/graphql-modules/src/di/decorators.ts +++ b/packages/graphql-modules/src/di/decorators.ts @@ -26,16 +26,19 @@ export function Injectable(options?: ProviderOptions): ClassDecorator { const existingMeta = readInjectableMetadata(target as any); const meta: InjectableMetadata = { - params: params.map((param, i) => { - const existingParam = existingMeta?.params?.[i]; - return { - type: existingParam?.type || param, - optional: - typeof existingParam?.optional === 'boolean' - ? existingParam.optional - : false, - }; - }), + params: + existingMeta?.params?.length > 0 && params.length === 0 + ? existingMeta?.params + : params.map((param, i) => { + const existingParam = existingMeta?.params?.[i]; + return { + type: existingParam?.type || param, + optional: + typeof existingParam?.optional === 'boolean' + ? existingParam.optional + : false, + }; + }), options: { ...(existingMeta?.options || {}), ...(options || {}),