mirror of
https://github.com/vale981/grapher
synced 2025-03-05 17:41:41 -05:00
Upgraded to 1.0.7
This commit is contained in:
parent
446d5eda86
commit
e9609b2df0
6 changed files with 59 additions and 3 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
## 1.0.7
|
||||||
|
- Optimized creating link for _id only, by fetching the object with the storage field only
|
||||||
|
- Added restrictFields in the exposure module to easily restrictFields
|
||||||
|
|
||||||
## 1.0.6
|
## 1.0.6
|
||||||
- Fixed exposure bug for static fetching
|
- Fixed exposure bug for static fetching
|
||||||
- Exporting useful components that allow you to customly build your data graph
|
- Exporting useful components that allow you to customly build your data graph
|
||||||
|
|
|
@ -70,6 +70,26 @@ const data = query.fetch() // will not care about the firewall at all.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Restrict fields easily
|
||||||
|
|
||||||
|
The reason for this function is that MongoDB queries do not allow fields like:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
iWantThisField: 1,
|
||||||
|
iDontWantThisOne: 0
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Using this function removes a bit of boilerplate code for you.
|
||||||
|
|
||||||
|
```
|
||||||
|
import {restrictFields} from 'meteor/cultofcoders:grapher';
|
||||||
|
|
||||||
|
Users.expose((filters, options, userId) => {
|
||||||
|
restrictFields(options, ['services', 'createdAt'];
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### Next step
|
### Next step
|
||||||
|
|
||||||
[Read about Query](query.md)
|
[Read about Query](query.md)
|
19
lib/exposure/lib/restrictFields.js
Normal file
19
lib/exposure/lib/restrictFields.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/**
|
||||||
|
* This is used to restrict some fields to some users, by passing the fields as array in the exposure object
|
||||||
|
* For example in an user exposure: restrictFields(options, ['services', 'createdAt'])
|
||||||
|
*
|
||||||
|
* @param options
|
||||||
|
* @param restrictedFields
|
||||||
|
*/
|
||||||
|
export default (options, restrictedFields) => {
|
||||||
|
if (options.fields) {
|
||||||
|
options.fields = _.omit(options.fields, ...restrictedFields);
|
||||||
|
} else {
|
||||||
|
let restrictingRules = {};
|
||||||
|
_.each(restrictedFields, field => {
|
||||||
|
restrictingRules[field] = 0
|
||||||
|
});
|
||||||
|
|
||||||
|
options.fields = _.extend({}, options.fields, restrictingRules)
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,9 +37,18 @@ _.extend(Mongo.Collection.prototype, {
|
||||||
throw new Meteor.Error(`There is no link ${name} for collection ${this._name}`);
|
throw new Meteor.Error(`There is no link ${name} for collection ${this._name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const linker = linkData[name];
|
||||||
let object = objectOrId;
|
let object = objectOrId;
|
||||||
if (typeof(objectOrId) == 'string') {
|
if (typeof(objectOrId) == 'string') {
|
||||||
object = this.findOne(objectOrId);
|
if (!linker.isVirtual()) {
|
||||||
|
object = this.findOne(objectOrId, {
|
||||||
|
fields: {
|
||||||
|
[linker.linkStorageField]: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
object = {_id: objectOrId};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return linkData[name].createLink(object);
|
return linkData[name].createLink(object);
|
||||||
|
|
|
@ -20,3 +20,7 @@ export {
|
||||||
export {
|
export {
|
||||||
default as applyFilterFunction
|
default as applyFilterFunction
|
||||||
} from './lib/query/lib/applyFilterFunction.js';
|
} from './lib/query/lib/applyFilterFunction.js';
|
||||||
|
|
||||||
|
export {
|
||||||
|
default as restrictFields
|
||||||
|
} from './lib/exposure/lib/restrictFields.js';
|
|
@ -1,6 +1,6 @@
|
||||||
Package.describe({
|
Package.describe({
|
||||||
name: 'cultofcoders:grapher',
|
name: 'cultofcoders:grapher',
|
||||||
version: '1.0.6',
|
version: '1.0.7',
|
||||||
// Brief, one-line summary of the package.
|
// Brief, one-line summary of the package.
|
||||||
summary: 'Grapher is a way of linking/joining collections. And fetching data in a GraphQL style.',
|
summary: 'Grapher is a way of linking/joining collections. And fetching data in a GraphQL style.',
|
||||||
// URL to the Git repository containing the source code for this package.
|
// URL to the Git repository containing the source code for this package.
|
||||||
|
|
Loading…
Add table
Reference in a new issue