Add new removeFromFragment function; fix collection.removeField

This commit is contained in:
SachaG 2017-05-14 11:08:07 +09:00
parent 5f7863c85e
commit 2981ca3e93
4 changed files with 12 additions and 4 deletions

View file

@ -11,7 +11,7 @@ export {
// collections
Collections, createCollection,
// fragments
Fragments, registerFragment, getFragment, getFragmentName, extendFragment,
Fragments, registerFragment, getFragment, getFragmentName, extendFragment, removeFromFragment,
// graphql
GraphQLSchema, addGraphQLSchema, addGraphQLQuery, addGraphQLMutation, addGraphQLResolvers, removeGraphQLResolver, addToGraphQLContext,
// headtags

View file

@ -14,7 +14,8 @@ SimpleSchema.extendOptions([
]);
/**
* @summary replacement for Collection2's attachSchema
* @summary replacement for Collection2's attachSchema. Pass either a schema, to
* initialize or replace the schema, or some fields, to extend the current schema
* @class Mongo.Collection
*/
Mongo.Collection.prototype.attachSchema = function (schemaOrFields) {
@ -57,7 +58,7 @@ Mongo.Collection.prototype.removeField = function (fieldName) {
var schema = _.omit(collection.simpleSchema()._schema, fieldName);
// add field schema to collection schema
collection.attachSchema(schema, {replace: true});
collection.attachSchema(new SimpleSchema(schema));
};
/**

View file

@ -28,6 +28,13 @@ export const extendFragment = (fragmentName, newProperties) => {
registerFragment(newFragmentText);
}
// remove a property from a fragment
export const removeFromFragment = (fragmentName, propertyName) => {
const fragment = Fragments[fragmentName];
const newFragmentText = fragment.fragmentText.replace(propertyName, '');
registerFragment(newFragmentText);
}
// get fragment name from fragment object
export const getFragmentName = fragment => fragment && fragment.definitions[0] && fragment.definitions[0].name.value;

View file

@ -19,5 +19,5 @@ export { getSetting } from './settings.js';
export { Strings, addStrings } from './strings.js';
export { configureStore, getActions, addAction, getReducers, addReducer, getMiddlewares, addMiddleware } from './redux.js';
export { Headtags } from './headtags.js';
export { Fragments, registerFragment, getFragment, getFragmentName, extendFragment } from './fragments.js';
export { Fragments, registerFragment, getFragment, getFragmentName, extendFragment, removeFromFragment } from './fragments.js';
export { createApolloClient } from './apollo.js';