123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', {
- value: true,
- });
- exports.mutationWithClientMutationId = mutationWithClientMutationId;
- var _graphql = require('graphql');
- function mutationWithClientMutationId(config) {
- const { name, inputFields, outputFields, mutateAndGetPayload } = config;
- const augmentedInputFields = () => ({
- ...(0, _graphql.resolveObjMapThunk)(inputFields),
- clientMutationId: {
- type: _graphql.GraphQLString,
- },
- });
- const augmentedOutputFields = () => ({
- ...(0, _graphql.resolveObjMapThunk)(outputFields),
- clientMutationId: {
- type: _graphql.GraphQLString,
- },
- });
- const outputType = new _graphql.GraphQLObjectType({
- name: name + 'Payload',
- fields: augmentedOutputFields,
- });
- const inputType = new _graphql.GraphQLInputObjectType({
- name: name + 'Input',
- fields: augmentedInputFields,
- });
- return {
- type: outputType,
- description: config.description,
- deprecationReason: config.deprecationReason,
- extensions: config.extensions,
- args: {
- input: {
- type: new _graphql.GraphQLNonNull(inputType),
- },
- },
- resolve: (_, { input }, context, info) => {
- const { clientMutationId } = input;
- const payload = mutateAndGetPayload(input, context, info);
- if (isPromiseLike(payload)) {
- return payload.then(injectClientMutationId);
- }
- return injectClientMutationId(payload);
- function injectClientMutationId(data) {
- if (typeof data === 'object' && data !== null) {
-
- data.clientMutationId = clientMutationId;
- }
- return data;
- }
- },
- };
- }
- function isPromiseLike(value) {
- return (
- typeof (value === null || value === void 0 ? void 0 : value.then) ===
- 'function'
- );
- }
|