From c30ce0a96d138e83d9c3859c7fb5b1886ae91a08 Mon Sep 17 00:00:00 2001 From: Douglas Muraoka Date: Fri, 27 Dec 2019 11:03:44 -0300 Subject: [PATCH 1/2] fix(GraphQL): Timeout when fetching huge collections Currently, when not specifying a `limit` to the GraphQL find-like query, it tries to fetch the entire collection of objects from a class. However, if the class contains a huge set of objects, it is never resolved and results in timeout. In order to solve this kind of problem, `parse-server` allows us to define a `maxLimit` parameter when initialized, which limits the maximum number of objects fetched per query; but it is not properly considered when the `limit` is undefined. --- src/GraphQL/helpers/objectsQueries.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/GraphQL/helpers/objectsQueries.js b/src/GraphQL/helpers/objectsQueries.js index 6b7a184dbb..e4d398fa4a 100644 --- a/src/GraphQL/helpers/objectsQueries.js +++ b/src/GraphQL/helpers/objectsQueries.js @@ -127,7 +127,10 @@ const findObjects = async ( if (skip) { options.skip = skip; } - if (config.maxLimit && options.limit > config.maxLimit) { + if ( + config.maxLimit && + (options.limit === undefined || options.limit > config.maxLimit) + ) { // Silently replace the limit on the query with the max configured options.limit = config.maxLimit; } From d7ed894b94214d64331ddac0b14b59afafed9e9c Mon Sep 17 00:00:00 2001 From: Douglas Muraoka Date: Fri, 27 Dec 2019 14:28:58 -0300 Subject: [PATCH 2/2] fix: Keep same behavior as REST fetch --- src/GraphQL/helpers/objectsQueries.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/GraphQL/helpers/objectsQueries.js b/src/GraphQL/helpers/objectsQueries.js index e4d398fa4a..3e918c98b6 100644 --- a/src/GraphQL/helpers/objectsQueries.js +++ b/src/GraphQL/helpers/objectsQueries.js @@ -119,6 +119,8 @@ const findObjects = async ( ) { if (limit || limit === 0) { options.limit = limit; + } else { + options.limit = 100; } if (options.limit !== 0) { if (order) { @@ -127,10 +129,7 @@ const findObjects = async ( if (skip) { options.skip = skip; } - if ( - config.maxLimit && - (options.limit === undefined || options.limit > config.maxLimit) - ) { + if (config.maxLimit && options.limit > config.maxLimit) { // Silently replace the limit on the query with the max configured options.limit = config.maxLimit; }