locatedError.mjs 726 B

12345678910111213141516
  1. import { GraphQLError } from './GraphQLError';
  2. /**
  3. * Given an arbitrary Error, presumably thrown while attempting to execute a
  4. * GraphQL operation, produce a new GraphQLError aware of the location in the
  5. * document responsible for the original Error.
  6. */
  7. export function locatedError(originalError, nodes, path) {
  8. // Note: this uses a brand-check to support GraphQL errors originating from
  9. // other contexts.
  10. if (originalError && Array.isArray(originalError.path)) {
  11. return originalError;
  12. }
  13. return new GraphQLError(originalError && originalError.message, originalError && originalError.nodes || nodes, originalError && originalError.source, originalError && originalError.positions, path, originalError);
  14. }