mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
![]() |
/*
|
||
|
|
||
|
Generic mutation wrapper to edit a document in a collection.
|
||
|
|
||
|
Sample mutation:
|
||
|
|
||
|
mutation moviesEdit($documentId: String, $set: MoviesInput, $unset: MoviesUnset) {
|
||
|
moviesEdit(documentId: $documentId, set: $set, unset: $unset) {
|
||
|
...MoviesEditFormFragment
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Arguments:
|
||
|
|
||
|
- documentId: the id of the document to modify
|
||
|
- set: an object containing all the fields to modify and their new values
|
||
|
- unset: an object containing the fields to unset
|
||
|
|
||
|
Child Props:
|
||
|
|
||
|
- editMutation(documentId, set, unset)
|
||
|
|
||
|
*/
|
||
|
|
||
|
import React, { Component } from 'react';
|
||
|
import { graphql } from 'react-apollo';
|
||
|
import gql from 'graphql-tag';
|
||
|
|
||
|
export default function withEdit(options) {
|
||
|
|
||
|
const {collection, fragmentName, fragment } = options,
|
||
|
collectionName = collection._name,
|
||
|
mutationName = collection.options.mutations.edit.name;
|
||
|
|
||
|
return graphql(gql`
|
||
|
mutation ${mutationName}($documentId: String, $set: ${collectionName}Input, $unset: ${collectionName}Unset) {
|
||
|
${mutationName}(documentId: $documentId, set: $set, unset: $unset) {
|
||
|
...${fragmentName}
|
||
|
}
|
||
|
}
|
||
|
${fragment}
|
||
|
`, {
|
||
|
props: ({ ownProps, mutate }) => ({
|
||
|
editMutation: (args) => {
|
||
|
const { documentId, set, unset } = args;
|
||
|
return mutate({
|
||
|
variables: { documentId, set, unset }
|
||
|
// note: updateQueries is not needed for editing documents
|
||
|
});
|
||
|
}
|
||
|
}),
|
||
|
});
|
||
|
|
||
|
}
|