UNPKG

iworks-core-api

Version:

iwroks server api module

83 lines (74 loc) 2.12 kB
import { GraphQLObjectType, GraphQLString, GraphQLInputObjectType, GraphQLBoolean, GraphQLInt, GraphQLFloat, GraphQLNonNull, } from 'graphql'; import omit from 'lodash/omit'; import { createPhase, updatePhase, deletePhase } from './phaseRepository'; const PhaseType = new GraphQLObjectType({ name: 'PhaseReturnType', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLInt) }, name: { type: new GraphQLNonNull(GraphQLString) }, sortOrder: { type: new GraphQLNonNull(GraphQLFloat) }, renovationProjectTplId: { type: new GraphQLNonNull(GraphQLString) }, }), }); const CreatePhaseInputType = new GraphQLInputObjectType({ name: 'CreatePhaseInput', fields: () => ({ name: { type: new GraphQLNonNull(GraphQLString) }, sortOrder: { type: new GraphQLNonNull(GraphQLFloat) }, renovationProjectTplId: { type: new GraphQLNonNull(GraphQLString) }, }), }); const UpdatePhaseInputType = new GraphQLInputObjectType({ name: 'UpdatePhaseInput', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLInt) }, name: { type: GraphQLString }, sortOrder: { type: GraphQLFloat }, renovationProjectTplId: { type: GraphQLString }, }), }); const DeletePhaseInputType = new GraphQLInputObjectType({ name: 'DeletePhaseInput', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLInt) }, parentId: { type: GraphQLString, description: 'Optional project tpl id', }, }), }); export default { createPhase: { type: PhaseType, args: { input: { type: new GraphQLNonNull(CreatePhaseInputType) }, }, resolve: (_, { input }) => createPhase(input), }, updatePhase: { type: PhaseType, args: { input: { type: new GraphQLNonNull(UpdatePhaseInputType) }, }, resolve: (_, { input }) => { const { id } = input; const data = omit(input, ['id']); return updatePhase(id, data); }, }, deletePhase: { type: GraphQLBoolean, args: { input: { type: new GraphQLNonNull(DeletePhaseInputType) }, }, resolve: (_, { input }) => deletePhase(input.id), }, };