import type { Maybe } from '../jsutils/Maybe' ; import { toError } from '../jsutils/toError' ; import type { ASTNode } from '../language/ast' ; import { GraphQLError } from './GraphQLError' ; /**
 * Given an arbitrary value, presumably thrown while attempting to execute a
 * GraphQL operation, produce a new GraphQLError aware of the location in the
 * document responsible for the original Error.
 */ export function locatedError ( rawOriginalError , nodes , path ? ) { const originalError = toError ( rawOriginalError ) ; if ( isLocatedGraphQLError ( originalError ) ) { return originalError ; } return new GraphQLError ( originalError . message , ( originalError as GraphQLError ) . nodes ?? nodes , ( originalError as GraphQLError ) . source , ( originalError as GraphQLError ) . positions , path , originalError ) ; } function isLocatedGraphQLError ( error ) { return Array . isArray ( error . path ) ; }