UNPKG

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