source.js 2.7 KB

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