1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.GraphQLError = GraphQLError;
|
7 |
|
8 | var _printError = require('./printError');
|
9 |
|
10 | var _location = require('../language/location');
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function GraphQLError( // eslint-disable-line no-redeclare
|
28 | message, nodes, source, positions, path, originalError, extensions) {
|
29 |
|
30 | var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined;
|
31 |
|
32 |
|
33 | var _source = source;
|
34 | if (!_source && _nodes) {
|
35 | var node = _nodes[0];
|
36 | _source = node && node.loc && node.loc.source;
|
37 | }
|
38 |
|
39 | var _positions = positions;
|
40 | if (!_positions && _nodes) {
|
41 | _positions = _nodes.reduce(function (list, node) {
|
42 | if (node.loc) {
|
43 | list.push(node.loc.start);
|
44 | }
|
45 | return list;
|
46 | }, []);
|
47 | }
|
48 | if (_positions && _positions.length === 0) {
|
49 | _positions = undefined;
|
50 | }
|
51 |
|
52 | var _locations = void 0;
|
53 | if (positions && source) {
|
54 | var providedSource = source;
|
55 | _locations = positions.map(function (pos) {
|
56 | return (0, _location.getLocation)(providedSource, pos);
|
57 | });
|
58 | } else if (_nodes) {
|
59 | _locations = _nodes.reduce(function (list, node) {
|
60 | if (node.loc) {
|
61 | list.push((0, _location.getLocation)(node.loc.source, node.loc.start));
|
62 | }
|
63 | return list;
|
64 | }, []);
|
65 | }
|
66 |
|
67 | Object.defineProperties(this, {
|
68 | message: {
|
69 | value: message,
|
70 |
|
71 |
|
72 |
|
73 | enumerable: true,
|
74 | writable: true
|
75 | },
|
76 | locations: {
|
77 |
|
78 |
|
79 | value: _locations || undefined,
|
80 |
|
81 |
|
82 |
|
83 | enumerable: true
|
84 | },
|
85 | path: {
|
86 |
|
87 |
|
88 | value: path || undefined,
|
89 |
|
90 |
|
91 |
|
92 | enumerable: true
|
93 | },
|
94 | nodes: {
|
95 | value: _nodes || undefined
|
96 | },
|
97 | source: {
|
98 | value: _source || undefined
|
99 | },
|
100 | positions: {
|
101 | value: _positions || undefined
|
102 | },
|
103 | originalError: {
|
104 | value: originalError
|
105 | },
|
106 | extensions: {
|
107 | value: extensions || originalError && originalError.extensions
|
108 | }
|
109 | });
|
110 |
|
111 |
|
112 | if (originalError && originalError.stack) {
|
113 | Object.defineProperty(this, 'stack', {
|
114 | value: originalError.stack,
|
115 | writable: true,
|
116 | configurable: true
|
117 | });
|
118 | } else if (Error.captureStackTrace) {
|
119 | Error.captureStackTrace(this, GraphQLError);
|
120 | } else {
|
121 | Object.defineProperty(this, 'stack', {
|
122 | value: Error().stack,
|
123 | writable: true,
|
124 | configurable: true
|
125 | });
|
126 | }
|
127 | }
|
128 |
|
129 | GraphQLError.prototype = Object.create(Error.prototype, {
|
130 | constructor: { value: GraphQLError },
|
131 | name: { value: 'GraphQLError' },
|
132 | toString: {
|
133 | value: function toString() {
|
134 | return (0, _printError.printError)(this);
|
135 | }
|
136 | }
|
137 | }); |
\ | No newline at end of file |