mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 17:41:43 -05:00
prettier commit :)
This commit is contained in:
parent
c932c4b5c7
commit
4dda9919fe
1 changed files with 17 additions and 12 deletions
|
@ -8,12 +8,11 @@ import { Utils, debug, debugGroup, debugGroupEnd, Connectors, getTypeName, getCo
|
|||
import { createError } from 'apollo-errors';
|
||||
|
||||
const defaultOptions = {
|
||||
cacheMaxAge: 300,
|
||||
cacheMaxAge: 300
|
||||
};
|
||||
|
||||
// note: for some reason changing resolverOptions to "options" throws error
|
||||
export function getDefaultResolvers(options) {
|
||||
|
||||
let typeName, collectionName, resolverOptions;
|
||||
if (typeof arguments[0] === 'object') {
|
||||
// new single-argument API
|
||||
|
@ -26,7 +25,7 @@ export function getDefaultResolvers(options) {
|
|||
typeName = getTypeName(collectionName);
|
||||
resolverOptions = { ...defaultOptions, ...arguments[1] };
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
// resolver for returning a list of documents based on a set of query terms
|
||||
|
||||
|
@ -48,7 +47,7 @@ export function getDefaultResolvers(options) {
|
|||
|
||||
// get currentUser and Users collection from context
|
||||
const { currentUser, Users } = context;
|
||||
|
||||
|
||||
// get collection based on collectionName argument
|
||||
const collection = context[collectionName];
|
||||
|
||||
|
@ -77,7 +76,7 @@ export function getDefaultResolvers(options) {
|
|||
debug('');
|
||||
|
||||
const data = { results: restrictedDocs };
|
||||
|
||||
|
||||
if (enableTotal) {
|
||||
// get total count of documents matching the selector
|
||||
data.totalCount = await Connectors.count(collection, selector);
|
||||
|
@ -85,7 +84,7 @@ export function getDefaultResolvers(options) {
|
|||
|
||||
// return results
|
||||
return data;
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
// resolver for returning a single document queried based on id or slug
|
||||
|
@ -111,9 +110,7 @@ export function getDefaultResolvers(options) {
|
|||
|
||||
// use Dataloader if doc is selected by documentId/_id
|
||||
const documentId = selector.documentId || selector._id;
|
||||
const doc = documentId
|
||||
? await collection.loader.load(documentId)
|
||||
: await Connectors.get(collection, selector);
|
||||
const doc = documentId ? await collection.loader.load(documentId) : await Connectors.get(collection, selector);
|
||||
|
||||
if (!doc) {
|
||||
if (allowNull) {
|
||||
|
@ -127,7 +124,15 @@ export function getDefaultResolvers(options) {
|
|||
// if collection has a checkAccess function defined, use it to perform a check on the current document
|
||||
// (will throw an error if check doesn't pass)
|
||||
if (collection.checkAccess) {
|
||||
Utils.performCheck(collection.checkAccess, currentUser, doc, collection, documentId, `${typeName}.read.single`, collectionName);
|
||||
Utils.performCheck(
|
||||
collection.checkAccess,
|
||||
currentUser,
|
||||
doc,
|
||||
collection,
|
||||
documentId,
|
||||
`${typeName}.read.single`,
|
||||
collectionName
|
||||
);
|
||||
}
|
||||
|
||||
const restrictedDoc = Users.restrictViewableFields(currentUser, collection, doc);
|
||||
|
@ -138,7 +143,7 @@ export function getDefaultResolvers(options) {
|
|||
|
||||
// filter out disallowed properties and return resulting document
|
||||
return { result: restrictedDoc };
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue