mirror of
https://github.com/vale981/grapher
synced 2025-03-04 17:11:38 -05:00
Updated recursiveFetch on client to handle scoped queries
This commit is contained in:
parent
5adca6e570
commit
6d329f5645
2 changed files with 15 additions and 24 deletions
|
@ -2,7 +2,7 @@ import CountSubscription from '../query/counts/countSubscription';
|
|||
import createGraph from '../query/lib/createGraph.js';
|
||||
import recursiveFetch from '../query/lib/recursiveFetch.js';
|
||||
import prepareForProcess from '../query/lib/prepareForProcess.js';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import {_} from 'meteor/underscore';
|
||||
import callWithPromise from '../query/lib/callWithPromise';
|
||||
import Base from './namedQuery.base';
|
||||
import {LocalCollection} from 'meteor/minimongo';
|
||||
|
@ -180,25 +180,11 @@ export default class extends Base {
|
|||
delete body.$options.skip;
|
||||
}
|
||||
|
||||
const rootNode = createGraph(this.collection, body, {
|
||||
scopeField: `_sub_${this.subscriptionHandle.subscriptionId}`,
|
||||
});
|
||||
|
||||
const subscriptionHandle = this.subscriptionHandle;
|
||||
// if query is scoped, all calls to find from recursive fetch should contain scopedQuery()
|
||||
if (this.options.scoped) {
|
||||
LocalCollection.prototype.__originalFind = LocalCollection.prototype.find;
|
||||
LocalCollection.prototype.find = function(query, ...args) {
|
||||
return LocalCollection.prototype.__originalFind.call(this, {$and: [subscriptionHandle.scopeQuery(), query || {}]}, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
const results = recursiveFetch(rootNode);
|
||||
|
||||
if (this.options.scoped) {
|
||||
LocalCollection.prototype.find = LocalCollection.prototype.__originalFind;
|
||||
}
|
||||
|
||||
return results;
|
||||
return recursiveFetch(
|
||||
createGraph(this.collection, body),
|
||||
undefined, {
|
||||
scoped: this.options.scoped,
|
||||
subscriptionHandle: this.subscriptionHandle,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,15 @@ import prepareForDelivery from './prepareForDelivery';
|
|||
*
|
||||
* @param node
|
||||
* @param parentObject
|
||||
* @param fetchOptions
|
||||
* @returns {*}
|
||||
*/
|
||||
function fetch(node, parentObject) {
|
||||
function fetch(node, parentObject, fetchOptions = {}) {
|
||||
let {filters, options} = applyProps(node);
|
||||
// add subscription filter
|
||||
if (fetchOptions.scoped && fetchOptions.subscriptionHandle) {
|
||||
_.extend(filters, fetchOptions.subscriptionHandle.scopeQuery());
|
||||
}
|
||||
|
||||
let results = [];
|
||||
|
||||
|
@ -53,8 +58,8 @@ function fetch(node, parentObject) {
|
|||
return results;
|
||||
}
|
||||
|
||||
export default (node, params) => {
|
||||
node.results = fetch(node);
|
||||
export default (node, params, fetchOptions) => {
|
||||
node.results = fetch(node, null, fetchOptions);
|
||||
|
||||
prepareForDelivery(node, params);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue