123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- /**
- * Contains a range of UTF-8 character offsets and token references that
- * identify the region of the source from which the AST derived.
- */
- export class Location {
- /**
- * The character offset at which this Node begins.
- */
- /**
- * The character offset at which this Node ends.
- */
- /**
- * The Token at which this Node begins.
- */
- /**
- * The Token at which this Node ends.
- */
- /**
- * The Source document the AST represents.
- */
- constructor(startToken, endToken, source) {
- this.start = startToken.start;
- this.end = endToken.end;
- this.startToken = startToken;
- this.endToken = endToken;
- this.source = source;
- }
- get [Symbol.toStringTag]() {
- return 'Location';
- }
- toJSON() {
- return {
- start: this.start,
- end: this.end,
- };
- }
- }
- /**
- * Represents a range of characters represented by a lexical token
- * within a Source.
- */
- export class Token {
- /**
- * The kind of Token.
- */
- /**
- * The character offset at which this Node begins.
- */
- /**
- * The character offset at which this Node ends.
- */
- /**
- * The 1-indexed line number on which this Token appears.
- */
- /**
- * The 1-indexed column number at which this Token begins.
- */
- /**
- * For non-punctuation tokens, represents the interpreted value of the token.
- *
- * Note: is undefined for punctuation tokens, but typed as string for
- * convenience in the parser.
- */
- /**
- * Tokens exist as nodes in a double-linked-list amongst all tokens
- * including ignored tokens. <SOF> is always the first node and <EOF>
- * the last.
- */
- constructor(kind, start, end, line, column, value) {
- this.kind = kind;
- this.start = start;
- this.end = end;
- this.line = line;
- this.column = column; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.value = value;
- this.prev = null;
- this.next = null;
- }
- get [Symbol.toStringTag]() {
- return 'Token';
- }
- toJSON() {
- return {
- kind: this.kind,
- value: this.value,
- line: this.line,
- column: this.column,
- };
- }
- }
- /**
- * The list of all possible AST node types.
- */
- /**
- * @internal
- */
- export const QueryDocumentKeys = {
- Name: [],
- Document: ['definitions'],
- OperationDefinition: [
- 'name',
- 'variableDefinitions',
- 'directives',
- 'selectionSet',
- ],
- VariableDefinition: ['variable', 'type', 'defaultValue', 'directives'],
- Variable: ['name'],
- SelectionSet: ['selections'],
- Field: ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
- Argument: ['name', 'value'],
- FragmentSpread: ['name', 'directives'],
- InlineFragment: ['typeCondition', 'directives', 'selectionSet'],
- FragmentDefinition: [
- 'name', // Note: fragment variable definitions are deprecated and will removed in v17.0.0
- 'variableDefinitions',
- 'typeCondition',
- 'directives',
- 'selectionSet',
- ],
- IntValue: [],
- FloatValue: [],
- StringValue: [],
- BooleanValue: [],
- NullValue: [],
- EnumValue: [],
- ListValue: ['values'],
- ObjectValue: ['fields'],
- ObjectField: ['name', 'value'],
- Directive: ['name', 'arguments'],
- NamedType: ['name'],
- ListType: ['type'],
- NonNullType: ['type'],
- SchemaDefinition: ['description', 'directives', 'operationTypes'],
- OperationTypeDefinition: ['type'],
- ScalarTypeDefinition: ['description', 'name', 'directives'],
- ObjectTypeDefinition: [
- 'description',
- 'name',
- 'interfaces',
- 'directives',
- 'fields',
- ],
- FieldDefinition: ['description', 'name', 'arguments', 'type', 'directives'],
- InputValueDefinition: [
- 'description',
- 'name',
- 'type',
- 'defaultValue',
- 'directives',
- ],
- InterfaceTypeDefinition: [
- 'description',
- 'name',
- 'interfaces',
- 'directives',
- 'fields',
- ],
- UnionTypeDefinition: ['description', 'name', 'directives', 'types'],
- EnumTypeDefinition: ['description', 'name', 'directives', 'values'],
- EnumValueDefinition: ['description', 'name', 'directives'],
- InputObjectTypeDefinition: ['description', 'name', 'directives', 'fields'],
- DirectiveDefinition: ['description', 'name', 'arguments', 'locations'],
- SchemaExtension: ['directives', 'operationTypes'],
- ScalarTypeExtension: ['name', 'directives'],
- ObjectTypeExtension: ['name', 'interfaces', 'directives', 'fields'],
- InterfaceTypeExtension: ['name', 'interfaces', 'directives', 'fields'],
- UnionTypeExtension: ['name', 'directives', 'types'],
- EnumTypeExtension: ['name', 'directives', 'values'],
- InputObjectTypeExtension: ['name', 'directives', 'fields'],
- };
- const kindValues = new Set(Object.keys(QueryDocumentKeys));
- /**
- * @internal
- */
- export function isNode(maybeNode) {
- const maybeKind =
- maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.kind;
- return typeof maybeKind === 'string' && kindValues.has(maybeKind);
- }
- /** Name */
- var OperationTypeNode;
- (function (OperationTypeNode) {
- OperationTypeNode['QUERY'] = 'query';
- OperationTypeNode['MUTATION'] = 'mutation';
- OperationTypeNode['SUBSCRIPTION'] = 'subscription';
- })(OperationTypeNode || (OperationTypeNode = {}));
- export { OperationTypeNode };
|