1 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
2 |
|
3 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4 |
|
5 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
6 |
|
7 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
8 |
|
9 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
10 |
|
11 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
12 |
|
13 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
14 |
|
15 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
16 |
|
17 | function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
18 |
|
19 | function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
20 |
|
21 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
22 |
|
23 | function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
24 |
|
25 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
26 |
|
27 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
28 |
|
29 |
|
30 |
|
31 | import isObjectLike from "../jsutils/isObjectLike.mjs";
|
32 | import { SYMBOL_TO_STRING_TAG } from "../polyfills/symbols.mjs";
|
33 | import { getLocation } from "../language/location.mjs";
|
34 | import { printLocation, printSourceLocation } from "../language/printLocation.mjs";
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export var GraphQLError = function (_Error) {
|
43 | _inherits(GraphQLError, _Error);
|
44 |
|
45 | var _super = _createSuper(GraphQLError);
|
46 |
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 | |
90 |
|
91 |
|
92 |
|
93 | |
94 |
|
95 |
|
96 | function GraphQLError(message, nodes, source, positions, path, originalError, extensions) {
|
97 | var _locations2, _source2, _positions2, _extensions2;
|
98 |
|
99 | var _this;
|
100 |
|
101 | _classCallCheck(this, GraphQLError);
|
102 |
|
103 | _this = _super.call(this, message);
|
104 |
|
105 | var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined;
|
106 |
|
107 |
|
108 | var _source = source;
|
109 |
|
110 | if (!_source && _nodes) {
|
111 | var _nodes$0$loc;
|
112 |
|
113 | _source = (_nodes$0$loc = _nodes[0].loc) === null || _nodes$0$loc === void 0 ? void 0 : _nodes$0$loc.source;
|
114 | }
|
115 |
|
116 | var _positions = positions;
|
117 |
|
118 | if (!_positions && _nodes) {
|
119 | _positions = _nodes.reduce(function (list, node) {
|
120 | if (node.loc) {
|
121 | list.push(node.loc.start);
|
122 | }
|
123 |
|
124 | return list;
|
125 | }, []);
|
126 | }
|
127 |
|
128 | if (_positions && _positions.length === 0) {
|
129 | _positions = undefined;
|
130 | }
|
131 |
|
132 | var _locations;
|
133 |
|
134 | if (positions && source) {
|
135 | _locations = positions.map(function (pos) {
|
136 | return getLocation(source, pos);
|
137 | });
|
138 | } else if (_nodes) {
|
139 | _locations = _nodes.reduce(function (list, node) {
|
140 | if (node.loc) {
|
141 | list.push(getLocation(node.loc.source, node.loc.start));
|
142 | }
|
143 |
|
144 | return list;
|
145 | }, []);
|
146 | }
|
147 |
|
148 | var _extensions = extensions;
|
149 |
|
150 | if (_extensions == null && originalError != null) {
|
151 | var originalExtensions = originalError.extensions;
|
152 |
|
153 | if (isObjectLike(originalExtensions)) {
|
154 | _extensions = originalExtensions;
|
155 | }
|
156 | }
|
157 |
|
158 | Object.defineProperties(_assertThisInitialized(_this), {
|
159 | name: {
|
160 | value: 'GraphQLError'
|
161 | },
|
162 | message: {
|
163 | value: message,
|
164 |
|
165 |
|
166 |
|
167 | enumerable: true,
|
168 | writable: true
|
169 | },
|
170 | locations: {
|
171 |
|
172 |
|
173 | value: (_locations2 = _locations) !== null && _locations2 !== void 0 ? _locations2 : undefined,
|
174 |
|
175 |
|
176 |
|
177 | enumerable: _locations != null
|
178 | },
|
179 | path: {
|
180 |
|
181 |
|
182 | value: path !== null && path !== void 0 ? path : undefined,
|
183 |
|
184 |
|
185 |
|
186 | enumerable: path != null
|
187 | },
|
188 | nodes: {
|
189 | value: _nodes !== null && _nodes !== void 0 ? _nodes : undefined
|
190 | },
|
191 | source: {
|
192 | value: (_source2 = _source) !== null && _source2 !== void 0 ? _source2 : undefined
|
193 | },
|
194 | positions: {
|
195 | value: (_positions2 = _positions) !== null && _positions2 !== void 0 ? _positions2 : undefined
|
196 | },
|
197 | originalError: {
|
198 | value: originalError
|
199 | },
|
200 | extensions: {
|
201 |
|
202 |
|
203 | value: (_extensions2 = _extensions) !== null && _extensions2 !== void 0 ? _extensions2 : undefined,
|
204 |
|
205 |
|
206 |
|
207 | enumerable: _extensions != null
|
208 | }
|
209 | });
|
210 |
|
211 | if (originalError !== null && originalError !== void 0 && originalError.stack) {
|
212 | Object.defineProperty(_assertThisInitialized(_this), 'stack', {
|
213 | value: originalError.stack,
|
214 | writable: true,
|
215 | configurable: true
|
216 | });
|
217 | return _possibleConstructorReturn(_this);
|
218 | }
|
219 |
|
220 |
|
221 | if (Error.captureStackTrace) {
|
222 | Error.captureStackTrace(_assertThisInitialized(_this), GraphQLError);
|
223 | } else {
|
224 | Object.defineProperty(_assertThisInitialized(_this), 'stack', {
|
225 | value: Error().stack,
|
226 | writable: true,
|
227 | configurable: true
|
228 | });
|
229 | }
|
230 |
|
231 | return _this;
|
232 | }
|
233 |
|
234 | _createClass(GraphQLError, [{
|
235 | key: "toString",
|
236 | value: function toString() {
|
237 | return printError(this);
|
238 | }
|
239 |
|
240 |
|
241 | }, {
|
242 | key: SYMBOL_TO_STRING_TAG,
|
243 | get: function get() {
|
244 | return 'Object';
|
245 | }
|
246 | }]);
|
247 |
|
248 | return GraphQLError;
|
249 | }( _wrapNativeSuper(Error));
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | export function printError(error) {
|
256 | var output = error.message;
|
257 |
|
258 | if (error.nodes) {
|
259 | for (var _i2 = 0, _error$nodes2 = error.nodes; _i2 < _error$nodes2.length; _i2++) {
|
260 | var node = _error$nodes2[_i2];
|
261 |
|
262 | if (node.loc) {
|
263 | output += '\n\n' + printLocation(node.loc);
|
264 | }
|
265 | }
|
266 | } else if (error.source && error.locations) {
|
267 | for (var _i4 = 0, _error$locations2 = error.locations; _i4 < _error$locations2.length; _i4++) {
|
268 | var location = _error$locations2[_i4];
|
269 | output += '\n\n' + printSourceLocation(error.source, location);
|
270 | }
|
271 | }
|
272 |
|
273 | return output;
|
274 | }
|