Merge branch 'devel' of https://github.com/VulcanJS/Vulcan into devel

This commit is contained in:
SachaG 2018-09-12 10:07:23 +09:00
commit 493380889b
7 changed files with 42 additions and 22 deletions

View file

@ -61,7 +61,7 @@ export default function withMulti(options) {
const { fragmentName, fragment } = extractFragmentInfo(options, collectionName);
const typeName = collection.options.typeName;
const resolverName = Utils.camelCaseify(Utils.pluralize(typeName));
const resolverName = collection.options.multiResolverName;
// build graphql query from options
const query = gql`
@ -189,7 +189,7 @@ export default function withMulti(options) {
: providedTerms;
return props.data.fetchMore({
variables: { terms: newTerms }, // ??? not sure about 'terms: newTerms'
variables: { input: { terms: newTerms } }, // ??? not sure about 'terms: newTerms'
updateQuery(previousResults, { fetchMoreResult }) {
// no more post to fetch
if (!fetchMoreResult.data) {

View file

@ -94,7 +94,7 @@ export function getDefaultResolvers(options) {
description: `A single ${typeName} document fetched by ID or slug`,
async resolver(root, { input = {} }, context, { cacheControl }) {
const { selector = {}, enableCache = false } = input;
const { selector = {}, enableCache = false, allowNull = false } = input;
debug('');
debugGroup(`--------------- start \x1b[35m${typeName} Single Resolver\x1b[0m ---------------`);
@ -116,9 +116,13 @@ export function getDefaultResolvers(options) {
: await Connectors.get(collection, selector);
if (!doc) {
if (allowNull) {
return { result: null };
} else {
const MissingDocumentError = createError('app.missing_document', { message: 'app.missing_document' });
throw new MissingDocumentError({ data: { documentId, slug } });
}
}
// 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)

View file

@ -37,7 +37,7 @@ Mongo.Collection.prototype.attachSchema = function (schemaOrFields) {
} else {
this.simpleSchema().extend(schemaOrFields)
}
}
};
/**
* @summary Add an additional field (or an array of fields) to a schema.
@ -134,6 +134,8 @@ export const createCollection = options => {
// add typeName if missing
collection.typeName = typeName;
collection.options.typeName = typeName;
collection.options.singleResolverName = Utils.camelCaseify(typeName);
collection.options.multiResolverName = Utils.camelCaseify(Utils.pluralize(typeName));
// add collectionName if missing
collection.collectionName = collectionName;
@ -158,13 +160,13 @@ export const createCollection = options => {
hidden: true,
type: Array,
isIntlData: true,
}
};
delete schema[`${fieldName}_intl`].intl;
schema[`${fieldName}_intl.$`] = {
type: getIntlString(),
}
};
// if original field is required, enable custom validation function instead of `optional` property
if (!schema[fieldName].optional) {
@ -287,9 +289,9 @@ export const createCollection = options => {
// console.log(parameters);
return parameters;
}
};
Collections.push(collection);
return collection;
}
};

View file

@ -50,6 +50,7 @@ SimpleSchema.extendOptions([
'options', // form options
'query', // field-specific data loading query
'selectable', // field can be used as part of a selector when querying for data
'unique', // field can be used as part of a selectorUnique when querying for data
'orderable', // field can be used to order results when querying for data
'intl', // set to `true` to make a field international

View file

@ -227,7 +227,17 @@ export const GraphQLSchema = {
}
if (field.selectable) {
// TODO
fields.selector.push({
name: fieldName,
type: inputFieldType,
});
}
if (field.selectable && field.unique) {
fields.selectorUnique.push({
name: fieldName,
type: inputFieldType,
});
}
if (field.orderable) {

View file

@ -2,7 +2,7 @@ import { Utils } from './utils';
export const convertToGraphQL = (fields, indentation) => {
return fields.length > 0 ? fields.map(f => fieldTemplate(f, indentation)).join(`\n`) : '';
}
};
export const arrayToGraphQL = fields => fields.map(f => `${f.name}: ${f.type}`).join(', ');
@ -19,7 +19,7 @@ export const getArguments = args => {
} else {
return '';
}
}
};
/* ------------------------------------- Generic Field Template ------------------------------------- */
@ -158,6 +158,8 @@ export const singleInputTemplate = ({ typeName }) =>
selector: ${typeName}SelectorUniqueInput
# Whether to enable caching for this query
enableCache: Boolean
# Return null instead of throwing MissingDocumentError
allowNull: Boolean
}`;
/*

View file

@ -205,6 +205,7 @@ Users.isAdminById = Users.isAdmin;
Users.getViewableFields = function (user, collection, document) {
return Utils.arrayToFields(_.compact(_.map(collection.simpleSchema()._schema,
(field, fieldName) => {
if (fieldName.indexOf('.$') > -1) return null;
return Users.canReadField(user, field, document) ? fieldName : null;
}
)));