text: import { addTool, findAll, findById } from '../domain/tool';
  import {
    stixDomainObjectAddRelation,
    stixDomainObjectCleanContext,
    stixDomainObjectDelete,
    stixDomainObjectDeleteRelation,
    stixDomainObjectEditContext,
    stixDomainObjectEditField,
  } from '../domain/stixDomainObject';
  import { batchKillChainPhases } from '../domain/stixCoreObject';
  import { RELATION_CREATED_BY, RELATION_OBJECT_LABEL, RELATION_OBJECT_MARKING } from '../schema/stixMetaRelationship';
  import { buildRefRelationKey } from '../schema/general';
  import { batchLoader } from '../database/middleware';
  
  const killChainPhaseLoader = batchLoader(batchKillChainPhases);
  
  const toolResolvers = {
    Query: {
      tool: (_, { id }, { user }) => findById(user, id),
      tools: (_, args, { user }) => findAll(user, args),
    },
    ToolsFilter: {
      createdBy: buildRefRelationKey(RELATION_CREATED_BY),
      markedBy: buildRefRelationKey(RELATION_OBJECT_MARKING),
      labelledBy: buildRefRelationKey(RELATION_OBJECT_LABEL),
    },
    Tool: {
      killChainPhases: (tool, _, { user }) => killChainPhaseLoader.load(tool.id, user),
    },
    Mutation: {
      toolEdit: (_, { id }, { user }) => ({
        delete: () => stixDomainObjectDelete(user, id),
        fieldPatch: ({ input, commitMessage }) => stixDomainObjectEditField(user, id, input, { commitMessage }),
        contextPatch: ({ input }) => stixDomainObjectEditContext(user, id, input),
        contextClean: () => stixDomainObjectCleanContext(user, id),
        relationAdd: ({ input }) => stixDomainObjectAddRelation(user, id, input),
        relationDelete: ({ toId, relationship_type: relationshipType }) =>
          stixDomainObjectDeleteRelation(user, id, toId, relationshipType),
      }),
      toolAdd: (_, { input }, { user }) => addTool(user, input),
    },
  };
  
  export default toolResolvers;
  