mirror of
https://github.com/vale981/grapher
synced 2025-03-12 13:56:38 -04:00
27 lines
779 B
JavaScript
27 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;
|
||
|
}
|