Merge pull request #1851 from MHerszak/withEdit-withRemove

Added getCollection to withEdit & withRemove
This commit is contained in:
Sacha Greif 2018-01-28 11:34:59 +09:00 committed by GitHub
commit 8e507552df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -25,18 +25,19 @@ Child Props:
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { getFragment, getFragmentName } from 'meteor/vulcan:core';
import { getFragment, getFragmentName, getCollection } from 'meteor/vulcan:core';
export default function withEdit(options) {
const {collection } = options,
const { collectionName } = options;
// get options
const collection = options.collection || getCollection(collectionName),
fragment = options.fragment || getFragment(options.fragmentName),
fragmentName = getFragmentName(fragment),
collectionName = collection.options.collectionName,
mutationName = collection.options.mutations.edit.name;
return graphql(gql`
mutation ${mutationName}($documentId: String, $set: ${collectionName}Input, $unset: ${collectionName}Unset) {
mutation ${mutationName}($documentId: String, $set: ${collection.options.collectionName}Input, $unset: ${collection.options.collectionName}Unset) {
${mutationName}(documentId: $documentId, set: $set, unset: $unset) {
...${fragmentName}
}

View file

@ -23,10 +23,12 @@ Child Props:
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { getCollection } from 'meteor/vulcan:core';
export default function withRemove(options) {
const { collection } = options,
const { collectionName } = options;
const collection = options.collection || getCollection(collectionName),
mutationName = collection.options.mutations.remove.name
return graphql(gql`