diff --git a/packages/cozy-client/src/CozyClient.js b/packages/cozy-client/src/CozyClient.js index 4893125ac3..cac59882f7 100644 --- a/packages/cozy-client/src/CozyClient.js +++ b/packages/cozy-client/src/CozyClient.js @@ -1065,14 +1065,15 @@ client.query(Q('io.cozy.bills'))`) * @param {QueryDefinition} definition QueryDefinition to be executed * @returns {Promise} */ - async requestQuery(definition) { - const mainResponse = await this.chain.request(definition) + async requestQuery(definition, options = {}) { + const mainResponse = await this.chain.request(definition, options) if (!definition.includes) { return mainResponse } const withIncluded = await this.fetchRelationships( mainResponse, - this.getIncludesRelationships(definition) + this.getIncludesRelationships(definition), + options ) return withIncluded } diff --git a/packages/cozy-client/src/StackLink.js b/packages/cozy-client/src/StackLink.js index 97e9a2fb92..62baa5cdbb 100644 --- a/packages/cozy-client/src/StackLink.js +++ b/packages/cozy-client/src/StackLink.js @@ -77,19 +77,20 @@ export default class StackLink extends CozyLink { this.stackClient = null } - request(operation, result, forward) { + request(operation, result, forward, options = {}) { if (operation.mutationType) { return this.executeMutation(operation, result, forward) } - return this.executeQuery(operation) + return this.executeQuery(operation, options) } /** * * @param {QueryDefinition} query - Query to execute * @returns {Promise} */ - executeQuery(query) { - const { doctype, selector, id, ids, referenced, ...options } = query + executeQuery(query, options = {}) { + const { doctype, selector, id, ids, referenced, ...opts } = query + const mergedOptions = { ...opts, ...options } if (!doctype) { logger.warn('Bad query', query) throw new Error('No doctype found in a query definition') @@ -102,12 +103,12 @@ export default class StackLink extends CozyLink { return collection.getAll(ids) } if (referenced) { - return collection.findReferencedBy(referenced, options) + return collection.findReferencedBy(referenced, mergedOptions) } if (hasFindOptions(query)) { - return collection.find(selector, options) + return collection.find(selector, mergedOptions) } else { - return collection.all(options) + return collection.all(mergedOptions) } } diff --git a/packages/cozy-stack-client/src/FileCollection.js b/packages/cozy-stack-client/src/FileCollection.js index 37444d16e8..bfc516278c 100644 --- a/packages/cozy-stack-client/src/FileCollection.js +++ b/packages/cozy-stack-client/src/FileCollection.js @@ -1228,6 +1228,7 @@ class FileCollection extends DocumentCollection { 'fields', 'includeDocs', 'includeFilePath', + 'signal', 'skipDeleted', 'skipTrashed' ]), @@ -1243,7 +1244,9 @@ class FileCollection extends DocumentCollection { last_seq: newLastSeq, pending, results - } = await this.stackClient.fetchJSON('GET', url) + } = await this.stackClient.fetchJSON('GET', url, null, { + signal: opts.signal + }) return { newLastSeq, pending, results } }