mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 09:31:43 -05:00
Add missing "}"; fix formatting
This commit is contained in:
parent
4296b67fec
commit
da300fe8a7
1 changed files with 14 additions and 18 deletions
|
@ -8,23 +8,20 @@ import { Utils, debug, debugGroup, debugGroupEnd } from 'meteor/vulcan:core';
|
|||
import { createError } from 'apollo-errors';
|
||||
|
||||
const defaultOptions = {
|
||||
cacheMaxAge: 300
|
||||
}
|
||||
cacheMaxAge: 300,
|
||||
};
|
||||
|
||||
export const getDefaultResolvers = (collectionName, resolverOptions = defaultOptions) => {
|
||||
|
||||
return {
|
||||
|
||||
// resolver for returning a list of documents based on a set of query terms
|
||||
|
||||
list: {
|
||||
|
||||
name: `${collectionName}List`,
|
||||
|
||||
description: `A list of ${collectionName} documents matching a set of query terms`,
|
||||
|
||||
async resolver(root, { terms = {}, enableCache = false }, context, { cacheControl }) {
|
||||
debug('')
|
||||
debug('');
|
||||
debugGroup(`--------------- start \x1b[35m${collectionName} list\x1b[0m resolver ---------------`);
|
||||
debug(`Options: ${JSON.stringify(resolverOptions)}`);
|
||||
debug(`Terms: ${JSON.stringify(terms)}`);
|
||||
|
@ -49,7 +46,9 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
|
|||
const docs = collection.find(selector, options).fetch();
|
||||
|
||||
// if collection has a checkAccess function defined, remove any documents that doesn't pass the check
|
||||
const viewableDocs = collection.checkAccess ? _.filter(docs, doc => collection.checkAccess(currentUser, doc)) : docs;
|
||||
const viewableDocs = collection.checkAccess
|
||||
? _.filter(docs, doc => collection.checkAccess(currentUser, doc))
|
||||
: docs;
|
||||
|
||||
// take the remaining documents and remove any fields that shouldn't be accessible
|
||||
const restrictedDocs = Users.restrictViewableFields(currentUser, collection, viewableDocs);
|
||||
|
@ -60,24 +59,22 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
|
|||
debug(`\x1b[33m=> ${restrictedDocs.length} documents returned\x1b[0m`);
|
||||
debugGroupEnd();
|
||||
debug(`--------------- end \x1b[35m${collectionName} list\x1b[0m resolver ---------------`);
|
||||
debug('')
|
||||
debug('');
|
||||
|
||||
// return results
|
||||
return restrictedDocs;
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
// resolver for returning a single document queried based on id or slug
|
||||
|
||||
single: {
|
||||
|
||||
name: `${collectionName}Single`,
|
||||
|
||||
description: `A single ${collectionName} document fetched by ID or slug`,
|
||||
|
||||
async resolver(root, { documentId, slug, enableCache = false }, context, { cacheControl }) {
|
||||
debug('')
|
||||
debug('');
|
||||
debugGroup(`--------------- start \x1b[35m${collectionName} single\x1b[0m resolver ---------------`);
|
||||
debug(`Options: ${JSON.stringify(resolverOptions)}`);
|
||||
debug(`DocumentId: ${documentId}`);
|
||||
|
@ -91,7 +88,9 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
|
|||
const collection = context[collectionName];
|
||||
|
||||
// don't use Dataloader if doc is selected by slug
|
||||
const doc = documentId ? await collection.loader.load(documentId) : (slug ? collection.findOne({ slug }) : collection.findOne());
|
||||
const doc = documentId
|
||||
? await collection.loader.load(documentId)
|
||||
: slug ? collection.findOne({ slug }) : collection.findOne();
|
||||
|
||||
if (!doc) {
|
||||
const MissingDocumentError = createError('app.missing_document', { message: 'app.missing_document' });
|
||||
|
@ -108,24 +107,21 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
|
|||
|
||||
debugGroupEnd();
|
||||
debug(`--------------- end \x1b[35m${collectionName} single\x1b[0m resolver ---------------`);
|
||||
debug('')
|
||||
debug('');
|
||||
|
||||
// filter out disallowed properties and return resulting document
|
||||
return restrictedDoc;
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
// resolver for returning the total number of documents matching a set of query terms
|
||||
|
||||
total: {
|
||||
|
||||
name: `${collectionName}Total`,
|
||||
|
||||
description: `The total count of ${collectionName} documents matching a set of query terms`,
|
||||
|
||||
async resolver(root, { terms, enableCache }, context, { cacheControl }) {
|
||||
|
||||
if (cacheControl && enableCache) {
|
||||
const maxAge = resolverOptions.cacheMaxAge || defaultOptions.cacheMaxAge;
|
||||
cacheControl.setCacheHint({ maxAge });
|
||||
|
@ -145,6 +141,6 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
|
|||
|
||||
return docs.count();
|
||||
},
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue