import { DocumentNode , OperationDefinitionNode , FieldNode } from 'graphql' ; export function getMutationDefinition ( doc ) { const isMutation = ( def ) : def is OperationDefinitionNode => def . kind === 'OperationDefinition' && def . operation === 'mutation' ; const defs = doc . definitions . filter ( isMutation ) ; if ( ! defs || ! defs [ 0 ] ) { throw new Error ( 'Must contain a mutation definition.' ) ; } return defs [ 0 ] ; } export function getFirstField ( def ) { return def . selectionSet . selections [ 0 ] as FieldNode ; }