UNPKG

simple-graphql

Version:

The simple way to generates GraphQL schemas and Sequelize models from your models definition.

41 lines 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const graphql_1 = require("graphql"); function mutationWithClientMutationId(config) { const { name, description, inputFields, outputFields, mutateAndGetPayload } = config; const augmentedInputFields = Object.assign({}, inputFields, { clientMutationId: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) } }); const augmentedOutputFields = Object.assign({}, outputFields, { clientMutationId: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) } }); const outputType = new graphql_1.GraphQLObjectType({ name: name + 'Payload', fields: augmentedOutputFields }); const inputType = new graphql_1.GraphQLInputObjectType({ name: name + 'Input', fields: augmentedInputFields }); return { type: outputType, description: description, args: { input: { type: new graphql_1.GraphQLNonNull(inputType) } }, resolve: function resolve(_, _ref, context, info) { const input = _ref.input; return Promise.resolve(mutateAndGetPayload(_, input, context, info)).then(function (payload) { payload = payload || {}; payload.clientMutationId = input.clientMutationId; return payload; }); } }; } exports.default = mutationWithClientMutationId; //# sourceMappingURL=mutationWithClientMutationId.js.map