mirror of
https://github.com/vale981/grapher
synced 2025-03-11 05:16:40 -04:00
26 lines
779 B
JavaScript
26 lines
779 B
JavaScript
import NamedQuery from './namedQuery.js';
|
|
import NamedQueryStore from './store';
|
|
|
|
/**
|
|
* @param name
|
|
* @param data
|
|
* @param args
|
|
*
|
|
* @returns NamedQuery
|
|
*/
|
|
export default (name, data, ...args) => {
|
|
if (_.keys(data).length > 1) {
|
|
throw new Meteor.Error('invalid-query', 'When using createNamedQuery you should only have one main root point.')
|
|
}
|
|
|
|
const entryPointName = _.first(_.keys(data));
|
|
const collection = Mongo.Collection.get(entryPointName);
|
|
if (!collection) {
|
|
throw new Meteor.Error('invalid-name', `We could not find any collection with the name ${entryPointName}`)
|
|
}
|
|
|
|
const namedQuery = new NamedQuery(name, collection, data[entryPointName], ...args);
|
|
NamedQueryStore.add(name, namedQuery);
|
|
|
|
return namedQuery;
|
|
}
|