1 | "use strict";
|
2 | var __assign = (this && this.__assign) || function () {
|
3 | __assign = Object.assign || function(t) {
|
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5 | s = arguments[i];
|
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7 | t[p] = s[p];
|
8 | }
|
9 | return t;
|
10 | };
|
11 | return __assign.apply(this, arguments);
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | var React = require("react");
|
15 | var PropTypes = require("prop-types");
|
16 | var apollo_utilities_1 = require("apollo-utilities");
|
17 | var react_apollo_1 = require("react-apollo");
|
18 | var aws_appsync_1 = require("aws-appsync");
|
19 | exports.graphqlMutation = function (mutation, cacheUpdateQuery, typename, idField, operationType) { return withGraphQL(reactMutator(mutation, cacheUpdateQuery, typename, idField, operationType)); };
|
20 | var withGraphQL = function (options) { return function (Component) {
|
21 | var document = options.document;
|
22 | var A = react_apollo_1.graphql(document, options)(Component);
|
23 | var B = function (props, context) {
|
24 | var client = context.client;
|
25 | return (React.createElement(A, __assign({}, props, { client: client })));
|
26 | };
|
27 | B.contextTypes = {
|
28 | client: PropTypes.object.isRequired
|
29 | };
|
30 | return B;
|
31 | }; };
|
32 | var reactMutator = function (mutation, cacheUpdateQuery, typename, idField, operationType) { return ({
|
33 | document: mutation,
|
34 | props: function (props) {
|
35 | var _a;
|
36 | var client = props.ownProps.client;
|
37 | var mutationName = apollo_utilities_1.resultKeyNameFromField(mutation.definitions[0].selectionSet.selections[0]);
|
38 | return _a = {},
|
39 | _a[mutationName] = function (variables) { return props.mutate(aws_appsync_1.buildMutation(client, mutation, variables, cacheUpdateQuery, typename, idField, operationType)); },
|
40 | _a;
|
41 | },
|
42 | }); };
|