From eaea2c2657ee1cf8654b3ba4316a42b97f253c88 Mon Sep 17 00:00:00 2001 From: jhon gil Date: Thu, 12 Sep 2024 08:30:05 -0500 Subject: [PATCH] fix(createResolversModel.ts): fix dynamic field loading logic to handle both object and non-object related fields properly --- src/utils/createResolversModel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/createResolversModel.ts b/src/utils/createResolversModel.ts index 9ac834e..76f12b0 100644 --- a/src/utils/createResolversModel.ts +++ b/src/utils/createResolversModel.ts @@ -81,7 +81,7 @@ const createResolvers = async (model: GQLModel, parsedModels: GQLModel[]) => { return `${rf.name}: async (parent: ${model.name}, _: null, { db, session }) => { ${unCapitalize(model.name)}DataLoader.${rf.name}Loader.clearAll() - return await ${unCapitalize(model.name)}DataLoader.${rf.name}Loader.load(parent.${relatedField}); + return await ${unCapitalize(model.name)}DataLoader.${rf.name}Loader.load(parent.${typeof relatedField=== 'object'?'id':relatedField}); }`; } else { return `${rf.name}: async (parent: ${model.name}, _: null, { db,session }) => {