UNPKG

2.74 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isSource = isSource;
7exports.Source = void 0;
8
9var _symbols = require("../polyfills/symbols.js");
10
11var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
12
13var _devAssert = _interopRequireDefault(require("../jsutils/devAssert.js"));
14
15var _instanceOf = _interopRequireDefault(require("../jsutils/instanceOf.js"));
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19function _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); } }
20
21function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
22
23/**
24 * A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
25 * optional, but they are useful for clients who store GraphQL documents in source files.
26 * For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
27 * be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
28 * The `line` and `column` properties in `locationOffset` are 1-indexed.
29 */
30var Source = /*#__PURE__*/function () {
31 function Source(body) {
32 var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GraphQL request';
33 var locationOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
34 line: 1,
35 column: 1
36 };
37 typeof body === 'string' || (0, _devAssert.default)(0, "Body must be a string. Received: ".concat((0, _inspect.default)(body), "."));
38 this.body = body;
39 this.name = name;
40 this.locationOffset = locationOffset;
41 this.locationOffset.line > 0 || (0, _devAssert.default)(0, 'line in locationOffset is 1-indexed and must be positive.');
42 this.locationOffset.column > 0 || (0, _devAssert.default)(0, 'column in locationOffset is 1-indexed and must be positive.');
43 } // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
44
45
46 _createClass(Source, [{
47 key: _symbols.SYMBOL_TO_STRING_TAG,
48 get: function get() {
49 return 'Source';
50 }
51 }]);
52
53 return Source;
54}();
55/**
56 * Test if the given value is a Source object.
57 *
58 * @internal
59 */
60
61
62exports.Source = Source;
63
64// eslint-disable-next-line no-redeclare
65function isSource(source) {
66 return (0, _instanceOf.default)(source, Source);
67}