github-pages-deploy-action/node_modules/graphql/error/locatedError.js.flow

32 lines
893 B
Plaintext
Raw Normal View History

2020-03-07 11:45:40 +08:00
// @flow strict
import { type ASTNode } from '../language/ast';
import { GraphQLError } from './GraphQLError';
/**
* Given an arbitrary Error, 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(
originalError: Error | GraphQLError,
nodes: ASTNode | $ReadOnlyArray<ASTNode> | void | null,
path?: ?$ReadOnlyArray<string | number>,
): GraphQLError {
// Note: this uses a brand-check to support GraphQL errors originating from
// other contexts.
if (Array.isArray(originalError.path)) {
return (originalError: any);
}
return new GraphQLError(
originalError.message,
(originalError: any).nodes ?? nodes,
(originalError: any).source,
(originalError: any).positions,
path,
originalError,
);
}