ast.js.flow 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. // @flow strict
  2. import { type Source } from './source';
  3. import { type TokenKindEnum } from './tokenKind';
  4. /**
  5. * Contains a range of UTF-8 character offsets and token references that
  6. * identify the region of the source from which the AST derived.
  7. */
  8. export type Location = {
  9. /**
  10. * The character offset at which this Node begins.
  11. */
  12. +start: number,
  13. /**
  14. * The character offset at which this Node ends.
  15. */
  16. +end: number,
  17. /**
  18. * The Token at which this Node begins.
  19. */
  20. +startToken: Token,
  21. /**
  22. * The Token at which this Node ends.
  23. */
  24. +endToken: Token,
  25. /**
  26. * The Source document the AST represents.
  27. */
  28. +source: Source,
  29. ...
  30. };
  31. /**
  32. * Represents a range of characters represented by a lexical token
  33. * within a Source.
  34. */
  35. export type Token = {
  36. /**
  37. * The kind of Token.
  38. */
  39. +kind: TokenKindEnum,
  40. /**
  41. * The character offset at which this Node begins.
  42. */
  43. +start: number,
  44. /**
  45. * The character offset at which this Node ends.
  46. */
  47. +end: number,
  48. /**
  49. * The 1-indexed line number on which this Token appears.
  50. */
  51. +line: number,
  52. /**
  53. * The 1-indexed column number at which this Token begins.
  54. */
  55. +column: number,
  56. /**
  57. * For non-punctuation tokens, represents the interpreted value of the token.
  58. */
  59. +value: string | void,
  60. /**
  61. * Tokens exist as nodes in a double-linked-list amongst all tokens
  62. * including ignored tokens. <SOF> is always the first node and <EOF>
  63. * the last.
  64. */
  65. +prev: Token | null,
  66. +next: Token | null,
  67. ...
  68. };
  69. /**
  70. * The list of all possible AST node types.
  71. */
  72. export type ASTNode =
  73. | NameNode
  74. | DocumentNode
  75. | OperationDefinitionNode
  76. | VariableDefinitionNode
  77. | VariableNode
  78. | SelectionSetNode
  79. | FieldNode
  80. | ArgumentNode
  81. | FragmentSpreadNode
  82. | InlineFragmentNode
  83. | FragmentDefinitionNode
  84. | IntValueNode
  85. | FloatValueNode
  86. | StringValueNode
  87. | BooleanValueNode
  88. | NullValueNode
  89. | EnumValueNode
  90. | ListValueNode
  91. | ObjectValueNode
  92. | ObjectFieldNode
  93. | DirectiveNode
  94. | NamedTypeNode
  95. | ListTypeNode
  96. | NonNullTypeNode
  97. | SchemaDefinitionNode
  98. | OperationTypeDefinitionNode
  99. | ScalarTypeDefinitionNode
  100. | ObjectTypeDefinitionNode
  101. | FieldDefinitionNode
  102. | InputValueDefinitionNode
  103. | InterfaceTypeDefinitionNode
  104. | UnionTypeDefinitionNode
  105. | EnumTypeDefinitionNode
  106. | EnumValueDefinitionNode
  107. | InputObjectTypeDefinitionNode
  108. | DirectiveDefinitionNode
  109. | SchemaExtensionNode
  110. | ScalarTypeExtensionNode
  111. | ObjectTypeExtensionNode
  112. | InterfaceTypeExtensionNode
  113. | UnionTypeExtensionNode
  114. | EnumTypeExtensionNode
  115. | InputObjectTypeExtensionNode;
  116. /**
  117. * Utility type listing all nodes indexed by their kind.
  118. */
  119. export type ASTKindToNode = {|
  120. Name: NameNode,
  121. Document: DocumentNode,
  122. OperationDefinition: OperationDefinitionNode,
  123. VariableDefinition: VariableDefinitionNode,
  124. Variable: VariableNode,
  125. SelectionSet: SelectionSetNode,
  126. Field: FieldNode,
  127. Argument: ArgumentNode,
  128. FragmentSpread: FragmentSpreadNode,
  129. InlineFragment: InlineFragmentNode,
  130. FragmentDefinition: FragmentDefinitionNode,
  131. IntValue: IntValueNode,
  132. FloatValue: FloatValueNode,
  133. StringValue: StringValueNode,
  134. BooleanValue: BooleanValueNode,
  135. NullValue: NullValueNode,
  136. EnumValue: EnumValueNode,
  137. ListValue: ListValueNode,
  138. ObjectValue: ObjectValueNode,
  139. ObjectField: ObjectFieldNode,
  140. Directive: DirectiveNode,
  141. NamedType: NamedTypeNode,
  142. ListType: ListTypeNode,
  143. NonNullType: NonNullTypeNode,
  144. SchemaDefinition: SchemaDefinitionNode,
  145. OperationTypeDefinition: OperationTypeDefinitionNode,
  146. ScalarTypeDefinition: ScalarTypeDefinitionNode,
  147. ObjectTypeDefinition: ObjectTypeDefinitionNode,
  148. FieldDefinition: FieldDefinitionNode,
  149. InputValueDefinition: InputValueDefinitionNode,
  150. InterfaceTypeDefinition: InterfaceTypeDefinitionNode,
  151. UnionTypeDefinition: UnionTypeDefinitionNode,
  152. EnumTypeDefinition: EnumTypeDefinitionNode,
  153. EnumValueDefinition: EnumValueDefinitionNode,
  154. InputObjectTypeDefinition: InputObjectTypeDefinitionNode,
  155. DirectiveDefinition: DirectiveDefinitionNode,
  156. SchemaExtension: SchemaExtensionNode,
  157. ScalarTypeExtension: ScalarTypeExtensionNode,
  158. ObjectTypeExtension: ObjectTypeExtensionNode,
  159. InterfaceTypeExtension: InterfaceTypeExtensionNode,
  160. UnionTypeExtension: UnionTypeExtensionNode,
  161. EnumTypeExtension: EnumTypeExtensionNode,
  162. InputObjectTypeExtension: InputObjectTypeExtensionNode,
  163. |};
  164. // Name
  165. export type NameNode = {
  166. +kind: 'Name',
  167. +loc?: Location,
  168. +value: string,
  169. ...
  170. };
  171. // Document
  172. export type DocumentNode = {
  173. +kind: 'Document',
  174. +loc?: Location,
  175. +definitions: $ReadOnlyArray<DefinitionNode>,
  176. ...
  177. };
  178. export type DefinitionNode =
  179. | ExecutableDefinitionNode
  180. | TypeSystemDefinitionNode
  181. | TypeSystemExtensionNode;
  182. export type ExecutableDefinitionNode =
  183. | OperationDefinitionNode
  184. | FragmentDefinitionNode;
  185. export type OperationDefinitionNode = {
  186. +kind: 'OperationDefinition',
  187. +loc?: Location,
  188. +operation: OperationTypeNode,
  189. +name?: NameNode,
  190. +variableDefinitions?: $ReadOnlyArray<VariableDefinitionNode>,
  191. +directives?: $ReadOnlyArray<DirectiveNode>,
  192. +selectionSet: SelectionSetNode,
  193. ...
  194. };
  195. export type OperationTypeNode = 'query' | 'mutation' | 'subscription';
  196. export type VariableDefinitionNode = {
  197. +kind: 'VariableDefinition',
  198. +loc?: Location,
  199. +variable: VariableNode,
  200. +type: TypeNode,
  201. +defaultValue?: ValueNode,
  202. +directives?: $ReadOnlyArray<DirectiveNode>,
  203. ...
  204. };
  205. export type VariableNode = {
  206. +kind: 'Variable',
  207. +loc?: Location,
  208. +name: NameNode,
  209. ...
  210. };
  211. export type SelectionSetNode = {
  212. kind: 'SelectionSet',
  213. loc?: Location,
  214. selections: $ReadOnlyArray<SelectionNode>,
  215. ...
  216. };
  217. export type SelectionNode = FieldNode | FragmentSpreadNode | InlineFragmentNode;
  218. export type FieldNode = {
  219. +kind: 'Field',
  220. +loc?: Location,
  221. +alias?: NameNode,
  222. +name: NameNode,
  223. +arguments?: $ReadOnlyArray<ArgumentNode>,
  224. +directives?: $ReadOnlyArray<DirectiveNode>,
  225. +selectionSet?: SelectionSetNode,
  226. ...
  227. };
  228. export type ArgumentNode = {
  229. +kind: 'Argument',
  230. +loc?: Location,
  231. +name: NameNode,
  232. +value: ValueNode,
  233. ...
  234. };
  235. // Fragments
  236. export type FragmentSpreadNode = {
  237. +kind: 'FragmentSpread',
  238. +loc?: Location,
  239. +name: NameNode,
  240. +directives?: $ReadOnlyArray<DirectiveNode>,
  241. ...
  242. };
  243. export type InlineFragmentNode = {
  244. +kind: 'InlineFragment',
  245. +loc?: Location,
  246. +typeCondition?: NamedTypeNode,
  247. +directives?: $ReadOnlyArray<DirectiveNode>,
  248. +selectionSet: SelectionSetNode,
  249. ...
  250. };
  251. export type FragmentDefinitionNode = {
  252. +kind: 'FragmentDefinition',
  253. +loc?: Location,
  254. +name: NameNode,
  255. // Note: fragment variable definitions are experimental and may be changed
  256. // or removed in the future.
  257. +variableDefinitions?: $ReadOnlyArray<VariableDefinitionNode>,
  258. +typeCondition: NamedTypeNode,
  259. +directives?: $ReadOnlyArray<DirectiveNode>,
  260. +selectionSet: SelectionSetNode,
  261. ...
  262. };
  263. // Values
  264. export type ValueNode =
  265. | VariableNode
  266. | IntValueNode
  267. | FloatValueNode
  268. | StringValueNode
  269. | BooleanValueNode
  270. | NullValueNode
  271. | EnumValueNode
  272. | ListValueNode
  273. | ObjectValueNode;
  274. export type IntValueNode = {
  275. +kind: 'IntValue',
  276. +loc?: Location,
  277. +value: string,
  278. ...
  279. };
  280. export type FloatValueNode = {
  281. +kind: 'FloatValue',
  282. +loc?: Location,
  283. +value: string,
  284. ...
  285. };
  286. export type StringValueNode = {
  287. +kind: 'StringValue',
  288. +loc?: Location,
  289. +value: string,
  290. +block?: boolean,
  291. ...
  292. };
  293. export type BooleanValueNode = {
  294. +kind: 'BooleanValue',
  295. +loc?: Location,
  296. +value: boolean,
  297. ...
  298. };
  299. export type NullValueNode = {
  300. +kind: 'NullValue',
  301. +loc?: Location,
  302. ...
  303. };
  304. export type EnumValueNode = {
  305. +kind: 'EnumValue',
  306. +loc?: Location,
  307. +value: string,
  308. ...
  309. };
  310. export type ListValueNode = {
  311. +kind: 'ListValue',
  312. +loc?: Location,
  313. +values: $ReadOnlyArray<ValueNode>,
  314. ...
  315. };
  316. export type ObjectValueNode = {
  317. +kind: 'ObjectValue',
  318. +loc?: Location,
  319. +fields: $ReadOnlyArray<ObjectFieldNode>,
  320. ...
  321. };
  322. export type ObjectFieldNode = {
  323. +kind: 'ObjectField',
  324. +loc?: Location,
  325. +name: NameNode,
  326. +value: ValueNode,
  327. ...
  328. };
  329. // Directives
  330. export type DirectiveNode = {
  331. +kind: 'Directive',
  332. +loc?: Location,
  333. +name: NameNode,
  334. +arguments?: $ReadOnlyArray<ArgumentNode>,
  335. ...
  336. };
  337. // Type Reference
  338. export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode;
  339. export type NamedTypeNode = {
  340. +kind: 'NamedType',
  341. +loc?: Location,
  342. +name: NameNode,
  343. ...
  344. };
  345. export type ListTypeNode = {
  346. +kind: 'ListType',
  347. +loc?: Location,
  348. +type: TypeNode,
  349. ...
  350. };
  351. export type NonNullTypeNode = {
  352. +kind: 'NonNullType',
  353. +loc?: Location,
  354. +type: NamedTypeNode | ListTypeNode,
  355. ...
  356. };
  357. // Type System Definition
  358. export type TypeSystemDefinitionNode =
  359. | SchemaDefinitionNode
  360. | TypeDefinitionNode
  361. | DirectiveDefinitionNode;
  362. export type SchemaDefinitionNode = {
  363. +kind: 'SchemaDefinition',
  364. +loc?: Location,
  365. +directives?: $ReadOnlyArray<DirectiveNode>,
  366. +operationTypes: $ReadOnlyArray<OperationTypeDefinitionNode>,
  367. ...
  368. };
  369. export type OperationTypeDefinitionNode = {
  370. +kind: 'OperationTypeDefinition',
  371. +loc?: Location,
  372. +operation: OperationTypeNode,
  373. +type: NamedTypeNode,
  374. ...
  375. };
  376. // Type Definition
  377. export type TypeDefinitionNode =
  378. | ScalarTypeDefinitionNode
  379. | ObjectTypeDefinitionNode
  380. | InterfaceTypeDefinitionNode
  381. | UnionTypeDefinitionNode
  382. | EnumTypeDefinitionNode
  383. | InputObjectTypeDefinitionNode;
  384. export type ScalarTypeDefinitionNode = {
  385. +kind: 'ScalarTypeDefinition',
  386. +loc?: Location,
  387. +description?: StringValueNode,
  388. +name: NameNode,
  389. +directives?: $ReadOnlyArray<DirectiveNode>,
  390. ...
  391. };
  392. export type ObjectTypeDefinitionNode = {
  393. +kind: 'ObjectTypeDefinition',
  394. +loc?: Location,
  395. +description?: StringValueNode,
  396. +name: NameNode,
  397. +interfaces?: $ReadOnlyArray<NamedTypeNode>,
  398. +directives?: $ReadOnlyArray<DirectiveNode>,
  399. +fields?: $ReadOnlyArray<FieldDefinitionNode>,
  400. ...
  401. };
  402. export type FieldDefinitionNode = {
  403. +kind: 'FieldDefinition',
  404. +loc?: Location,
  405. +description?: StringValueNode,
  406. +name: NameNode,
  407. +arguments?: $ReadOnlyArray<InputValueDefinitionNode>,
  408. +type: TypeNode,
  409. +directives?: $ReadOnlyArray<DirectiveNode>,
  410. ...
  411. };
  412. export type InputValueDefinitionNode = {
  413. +kind: 'InputValueDefinition',
  414. +loc?: Location,
  415. +description?: StringValueNode,
  416. +name: NameNode,
  417. +type: TypeNode,
  418. +defaultValue?: ValueNode,
  419. +directives?: $ReadOnlyArray<DirectiveNode>,
  420. ...
  421. };
  422. export type InterfaceTypeDefinitionNode = {
  423. +kind: 'InterfaceTypeDefinition',
  424. +loc?: Location,
  425. +description?: StringValueNode,
  426. +name: NameNode,
  427. +directives?: $ReadOnlyArray<DirectiveNode>,
  428. +fields?: $ReadOnlyArray<FieldDefinitionNode>,
  429. ...
  430. };
  431. export type UnionTypeDefinitionNode = {
  432. +kind: 'UnionTypeDefinition',
  433. +loc?: Location,
  434. +description?: StringValueNode,
  435. +name: NameNode,
  436. +directives?: $ReadOnlyArray<DirectiveNode>,
  437. +types?: $ReadOnlyArray<NamedTypeNode>,
  438. ...
  439. };
  440. export type EnumTypeDefinitionNode = {
  441. +kind: 'EnumTypeDefinition',
  442. +loc?: Location,
  443. +description?: StringValueNode,
  444. +name: NameNode,
  445. +directives?: $ReadOnlyArray<DirectiveNode>,
  446. +values?: $ReadOnlyArray<EnumValueDefinitionNode>,
  447. ...
  448. };
  449. export type EnumValueDefinitionNode = {
  450. +kind: 'EnumValueDefinition',
  451. +loc?: Location,
  452. +description?: StringValueNode,
  453. +name: NameNode,
  454. +directives?: $ReadOnlyArray<DirectiveNode>,
  455. ...
  456. };
  457. export type InputObjectTypeDefinitionNode = {
  458. +kind: 'InputObjectTypeDefinition',
  459. +loc?: Location,
  460. +description?: StringValueNode,
  461. +name: NameNode,
  462. +directives?: $ReadOnlyArray<DirectiveNode>,
  463. +fields?: $ReadOnlyArray<InputValueDefinitionNode>,
  464. ...
  465. };
  466. // Directive Definitions
  467. export type DirectiveDefinitionNode = {
  468. +kind: 'DirectiveDefinition',
  469. +loc?: Location,
  470. +description?: StringValueNode,
  471. +name: NameNode,
  472. +arguments?: $ReadOnlyArray<InputValueDefinitionNode>,
  473. +repeatable: boolean,
  474. +locations: $ReadOnlyArray<NameNode>,
  475. ...
  476. };
  477. // Type System Extensions
  478. export type TypeSystemExtensionNode = SchemaExtensionNode | TypeExtensionNode;
  479. export type SchemaExtensionNode = {
  480. +kind: 'SchemaExtension',
  481. +loc?: Location,
  482. +directives?: $ReadOnlyArray<DirectiveNode>,
  483. +operationTypes?: $ReadOnlyArray<OperationTypeDefinitionNode>,
  484. ...
  485. };
  486. // Type Extensions
  487. export type TypeExtensionNode =
  488. | ScalarTypeExtensionNode
  489. | ObjectTypeExtensionNode
  490. | InterfaceTypeExtensionNode
  491. | UnionTypeExtensionNode
  492. | EnumTypeExtensionNode
  493. | InputObjectTypeExtensionNode;
  494. export type ScalarTypeExtensionNode = {
  495. +kind: 'ScalarTypeExtension',
  496. +loc?: Location,
  497. +name: NameNode,
  498. +directives?: $ReadOnlyArray<DirectiveNode>,
  499. ...
  500. };
  501. export type ObjectTypeExtensionNode = {
  502. +kind: 'ObjectTypeExtension',
  503. +loc?: Location,
  504. +name: NameNode,
  505. +interfaces?: $ReadOnlyArray<NamedTypeNode>,
  506. +directives?: $ReadOnlyArray<DirectiveNode>,
  507. +fields?: $ReadOnlyArray<FieldDefinitionNode>,
  508. ...
  509. };
  510. export type InterfaceTypeExtensionNode = {
  511. +kind: 'InterfaceTypeExtension',
  512. +loc?: Location,
  513. +name: NameNode,
  514. +directives?: $ReadOnlyArray<DirectiveNode>,
  515. +fields?: $ReadOnlyArray<FieldDefinitionNode>,
  516. ...
  517. };
  518. export type UnionTypeExtensionNode = {
  519. +kind: 'UnionTypeExtension',
  520. +loc?: Location,
  521. +name: NameNode,
  522. +directives?: $ReadOnlyArray<DirectiveNode>,
  523. +types?: $ReadOnlyArray<NamedTypeNode>,
  524. ...
  525. };
  526. export type EnumTypeExtensionNode = {
  527. +kind: 'EnumTypeExtension',
  528. +loc?: Location,
  529. +name: NameNode,
  530. +directives?: $ReadOnlyArray<DirectiveNode>,
  531. +values?: $ReadOnlyArray<EnumValueDefinitionNode>,
  532. ...
  533. };
  534. export type InputObjectTypeExtensionNode = {
  535. +kind: 'InputObjectTypeExtension',
  536. +loc?: Location,
  537. +name: NameNode,
  538. +directives?: $ReadOnlyArray<DirectiveNode>,
  539. +fields?: $ReadOnlyArray<InputValueDefinitionNode>,
  540. ...
  541. };