import { CACHE_KEYWORD , NODE_TYPES } from 'common/enums' ; import { environment } from 'common/environment' ; import { UserNotFoundError } from 'common/errors' ; import { fromGlobalId } from 'common/utils' ; import { MutationToMergeTagsResolver } from 'definitions' ; const resolver = async ( root , { input : { ids , content } } , { viewer , dataSources : { atomService , tagService , userService } } ) => { if ( ! environment . mattyId ) { throw new UserNotFoundError ( 'could not find Matty' ) ; } const tagIds = ids . map ( ( id ) => fromGlobalId ( id ) . id ) ; const newTag = await tagService . mergeTags ( { tagIds , content , creator : environment . mattyId , editors : [ environment . mattyId ] , owner : environment . mattyId , } ) ; await Promise . all ( tagIds . map ( ( id ) => atomService . deleteSearch ( { table : 'tag' , id } ) ) ) ; newTag [ CACHE_KEYWORD ] = tagIds . map ( ( id ) => ( { id , type : NODE_TYPES . Tag } ) ) ; return newTag ; } ; export default resolver ;