UNPKG

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