source.mjs 2.3 KB

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