2016-11-26 11:17:43 +09:00
|
|
|
/*
|
|
|
|
|
|
|
|
Generic mutation wrapper to remove a document from a collection.
|
|
|
|
|
|
|
|
Sample mutation:
|
|
|
|
|
|
|
|
mutation moviesRemove($documentId: String) {
|
|
|
|
moviesEdit(documentId: $documentId) {
|
|
|
|
...MoviesRemoveFormFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
|
|
|
- documentId: the id of the document to remove
|
|
|
|
|
|
|
|
Child Props:
|
|
|
|
|
|
|
|
- removeMutation(documentId)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { graphql } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
|
|
|
|
export default function withRemove(options) {
|
|
|
|
|
2016-12-05 09:29:49 +09:00
|
|
|
const { collection } = options,
|
|
|
|
mutationName = collection.options.mutations.remove.name
|
2016-11-26 11:17:43 +09:00
|
|
|
|
|
|
|
return graphql(gql`
|
|
|
|
mutation ${mutationName}($documentId: String) {
|
|
|
|
${mutationName}(documentId: $documentId) {
|
2016-12-05 09:29:49 +09:00
|
|
|
_id
|
2016-11-26 11:17:43 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
2017-01-21 10:02:03 +09:00
|
|
|
alias: 'withRemove',
|
2016-11-26 11:17:43 +09:00
|
|
|
props: ({ ownProps, mutate }) => ({
|
|
|
|
removeMutation: ({ documentId }) => {
|
|
|
|
return mutate({
|
2016-12-05 09:29:49 +09:00
|
|
|
variables: { documentId }
|
2016-11-30 10:31:19 +01:00
|
|
|
});
|
2016-11-26 11:17:43 +09:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|