import { DocumentNode } from 'graphql' ; import { setUpdateMetadata } from '../metadata/update' ; import { getNameOfMutation , getMutation , isMutation } from '../mutation' ; import { UpdateMethod } from '../types/update' ; import { MutationObject } from '../types/mutation' ; export function Update ( mutation ) { return function ( target , name , _descriptor ) { let mutationName ; if ( isMutation ( mutation ) ) { const document = getMutation ( mutation ) ; if ( ! document ) { throw new Error ( `Mutation ${ ( mutation as any ) . name } is missing a static property 'mutation'` ) ; } mutationName = getNameOfMutation ( document ) ; } else if ( typeof mutation === 'string' ) { mutationName = mutation ; } else { mutationName = getNameOfMutation ( mutation ) ; } setUpdateMetadata ( target , name , mutationName ) ; } ; }