source.mjs 1.0 KB

1234567891011121314151617181920212223
  1. import devAssert from '../jsutils/devAssert';
  2. import defineToStringTag from '../jsutils/defineToStringTag';
  3. /**
  4. * A representation of source input to GraphQL.
  5. * `name` and `locationOffset` are optional. They are useful for clients who
  6. * store GraphQL documents in source files; for example, if the GraphQL input
  7. * starts at line 40 in a file named Foo.graphql, it might be useful for name to
  8. * be "Foo.graphql" and location to be `{ line: 40, column: 0 }`.
  9. * line and column in locationOffset are 1-indexed
  10. */
  11. export var Source = function Source(body, name, locationOffset) {
  12. this.body = body;
  13. this.name = name || 'GraphQL request';
  14. this.locationOffset = locationOffset || {
  15. line: 1,
  16. column: 1
  17. };
  18. this.locationOffset.line > 0 || devAssert(0, 'line in locationOffset is 1-indexed and must be positive');
  19. this.locationOffset.column > 0 || devAssert(0, 'column in locationOffset is 1-indexed and must be positive');
  20. }; // Conditionally apply `[Symbol.toStringTag]` if `Symbol`s are supported
  21. defineToStringTag(Source);