Skip to content

Commit 937c959

Browse files
fix(list-resolver): Fix a bug when an empty where is given to a resolver. Due to an implementation detail in graphql-sequelize we have to avoid optimizing in that case. Should not be a big deal as this should never be the case for n+1 queries.
1 parent 5833ebc commit 937c959

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/createListResolver.ts

+6
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ async function trimAndOptimizeFindOptions({
143143
graphqlTypeDeclaration,
144144
info,
145145
models,
146+
args,
146147
}: {
147148
findOptions: FindOptions<any>
148149
graphqlTypeDeclaration: any
149150
info: any
150151
models: any
152+
args: any
151153
}) {
152154
const trimedFindOptions =
153155
graphqlTypeDeclaration.list &&
@@ -175,6 +177,9 @@ async function trimAndOptimizeFindOptions({
175177
// It does not differenciate between an empty where and a where with properties so we have to remove it.
176178
if (
177179
trimedFindOptions.where &&
180+
// We can only optimize the where if it was not passed as an argument.
181+
// This is due to an implementation detail of /node_modules/graphql-sequelize/lib/resolver.js:28:39
182+
!args.where &&
178183
// Symbols like [Op.and] are not returned by Object.keys and must be handled separately.
179184
Object.getOwnPropertySymbols(trimedFindOptions.where).length === 0 &&
180185
Object.keys(trimedFindOptions.where).length === 0
@@ -335,6 +340,7 @@ export default function createListResolver(
335340
graphqlTypeDeclaration,
336341
info,
337342
models,
343+
args,
338344
})
339345
},
340346
after: async (

0 commit comments

Comments
 (0)