grammar.js.flow 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. // @flow strict
  2. export type GraphQLGrammarType = {|
  3. [name: string]: GraphQLGrammarRule,
  4. |};
  5. export type GraphQLGrammarRuleName = string;
  6. export type GraphQLGrammarRuleConstraint =
  7. | GraphQLGrammarTokenConstraint
  8. | GraphQLGrammarOfTypeConstraint
  9. | GraphQLGrammarListOfTypeConstraint
  10. | GraphQLGrammarPeekConstraint;
  11. export type GraphQLGrammarConstraintsSet = Array<
  12. GraphQLGrammarRuleName | GraphQLGrammarRuleConstraint,
  13. >;
  14. export type GraphQLGrammarRule =
  15. | GraphQLGrammarRuleName
  16. | GraphQLGrammarRuleConstraint
  17. | GraphQLGrammarConstraintsSet;
  18. export interface GraphQLGrammarBaseRuleConstraint {
  19. butNot?:
  20. | ?GraphQLGrammarTokenConstraint
  21. | ?Array<GraphQLGrammarTokenConstraint>;
  22. optional?: boolean;
  23. eatNextOnFail?: boolean;
  24. }
  25. export interface GraphQLGrammarTokenConstraint
  26. extends GraphQLGrammarBaseRuleConstraint {
  27. token:
  28. | '!'
  29. | '$'
  30. | '&'
  31. | '('
  32. | ')'
  33. | '...'
  34. | ':'
  35. | '='
  36. | '@'
  37. | '['
  38. | ']'
  39. | '{'
  40. | '}'
  41. | '|'
  42. | 'Name'
  43. | 'Int'
  44. | 'Float'
  45. | 'String'
  46. | 'BlockString'
  47. | 'Comment';
  48. ofValue?: ?string;
  49. oneOf?: ?Array<string>;
  50. tokenName?: string;
  51. definitionName?: boolean;
  52. typeName?: boolean;
  53. }
  54. export interface GraphQLGrammarOfTypeConstraint
  55. extends GraphQLGrammarBaseRuleConstraint {
  56. ofType: GraphQLGrammarRule;
  57. tokenName?: string;
  58. }
  59. export interface GraphQLGrammarListOfTypeConstraint
  60. extends GraphQLGrammarBaseRuleConstraint {
  61. listOfType: GraphQLGrammarRuleName;
  62. }
  63. export interface GraphQLGrammarPeekConstraint
  64. extends GraphQLGrammarBaseRuleConstraint {
  65. peek: Array<GraphQLGrammarPeekConstraintCondition>;
  66. }
  67. export interface GraphQLGrammarPeekConstraintCondition {
  68. ifCondition: GraphQLGrammarTokenConstraint;
  69. expect: GraphQLGrammarRule;
  70. end?: boolean;
  71. }
  72. const grammar: GraphQLGrammarType = ({
  73. Name: { token: 'Name' },
  74. String: { token: 'String' },
  75. BlockString: { token: 'BlockString' },
  76. Document: { listOfType: 'Definition' },
  77. Definition: {
  78. peek: [
  79. {
  80. ifCondition: {
  81. token: 'Name',
  82. oneOf: ['query', 'mutation', 'subscription'],
  83. },
  84. expect: 'OperationDefinition',
  85. },
  86. {
  87. ifCondition: { token: 'Name', ofValue: 'fragment' },
  88. expect: 'FragmentDefinition',
  89. },
  90. {
  91. ifCondition: {
  92. token: 'Name',
  93. oneOf: [
  94. 'schema',
  95. 'scalar',
  96. 'type',
  97. 'interface',
  98. 'union',
  99. 'enum',
  100. 'input',
  101. 'directive',
  102. ],
  103. },
  104. expect: 'TypeSystemDefinition',
  105. },
  106. {
  107. ifCondition: { token: 'Name', ofValue: 'extend' },
  108. expect: 'TypeSystemExtension',
  109. },
  110. {
  111. ifCondition: { token: '{' },
  112. expect: 'OperationDefinition',
  113. },
  114. {
  115. ifCondition: 'String',
  116. expect: 'TypeSystemDefinition',
  117. },
  118. {
  119. ifCondition: 'BlockString',
  120. expect: 'TypeSystemDefinition',
  121. },
  122. ],
  123. },
  124. OperationDefinition: {
  125. peek: [
  126. {
  127. ifCondition: { token: '{' },
  128. expect: 'SelectionSet',
  129. },
  130. {
  131. ifCondition: {
  132. token: 'Name',
  133. oneOf: ['query', 'mutation', 'subscription'],
  134. },
  135. expect: [
  136. 'OperationType',
  137. {
  138. token: 'Name',
  139. optional: true,
  140. tokenName: 'OperationName',
  141. definitionName: true,
  142. },
  143. { ofType: 'VariableDefinitions', optional: true },
  144. { ofType: 'Directives', optional: true },
  145. 'SelectionSet',
  146. ],
  147. },
  148. ],
  149. },
  150. OperationType: {
  151. ofType: 'OperationTypeName',
  152. },
  153. OperationTypeName: {
  154. token: 'Name',
  155. oneOf: ['query', 'mutation', 'subscription'],
  156. definitionName: true,
  157. },
  158. SelectionSet: [{ token: '{' }, { listOfType: 'Selection' }, { token: '}' }],
  159. Selection: {
  160. peek: [
  161. {
  162. ifCondition: { token: '...' },
  163. expect: 'Fragment',
  164. },
  165. {
  166. ifCondition: { token: 'Name' },
  167. expect: 'Field',
  168. },
  169. ],
  170. },
  171. Field: [
  172. {
  173. ofType: 'Alias',
  174. optional: true,
  175. eatNextOnFail: true,
  176. definitionName: true,
  177. },
  178. { token: 'Name', tokenName: 'FieldName', definitionName: true },
  179. { ofType: 'Arguments', optional: true },
  180. { ofType: 'Directives', optional: true },
  181. { ofType: 'SelectionSet', optional: true },
  182. ],
  183. Arguments: [{ token: '(' }, { listOfType: 'Argument' }, { token: ')' }],
  184. Argument: [
  185. { token: 'Name', tokenName: 'ArgumentName', definitionName: true },
  186. { token: ':' },
  187. 'Value',
  188. ],
  189. Alias: [
  190. { token: 'Name', tokenName: 'AliasName', definitionName: true },
  191. { token: ':' },
  192. ],
  193. Fragment: [
  194. { token: '...' },
  195. {
  196. peek: [
  197. {
  198. ifCondition: 'FragmentName',
  199. expect: 'FragmentSpread',
  200. },
  201. {
  202. ifCondition: { token: 'Name', ofValue: 'on' },
  203. expect: 'InlineFragment',
  204. },
  205. {
  206. ifCondition: { token: '@' },
  207. expect: 'InlineFragment',
  208. },
  209. {
  210. ifCondition: { token: '{' },
  211. expect: 'InlineFragment',
  212. },
  213. ],
  214. },
  215. ],
  216. FragmentSpread: ['FragmentName', { ofType: 'Directives', optional: true }],
  217. FragmentDefinition: [
  218. {
  219. token: 'Name',
  220. ofValue: 'fragment',
  221. tokenName: 'FragmentDefinitionKeyword',
  222. },
  223. 'FragmentName',
  224. 'TypeCondition',
  225. { ofType: 'Directives', optional: true },
  226. 'SelectionSet',
  227. ],
  228. FragmentName: {
  229. token: 'Name',
  230. butNot: { token: 'Name', ofValue: 'on' },
  231. definitionName: true,
  232. },
  233. TypeCondition: [
  234. { token: 'Name', ofValue: 'on', tokenName: 'OnKeyword' },
  235. 'TypeName',
  236. ],
  237. InlineFragment: [
  238. { ofType: 'TypeCondition', optional: true },
  239. { ofType: 'Directives', optional: true },
  240. 'SelectionSet',
  241. ],
  242. Value: {
  243. peek: [
  244. {
  245. ifCondition: { token: '$' },
  246. expect: 'Variable',
  247. },
  248. {
  249. ifCondition: 'IntValue',
  250. expect: { ofType: 'IntValue', tokenName: 'NumberValue' },
  251. },
  252. {
  253. ifCondition: 'FloatValue',
  254. expect: { ofType: 'FloatValue', tokenName: 'NumberValue' },
  255. },
  256. {
  257. ifCondition: 'BooleanValue',
  258. expect: { ofType: 'BooleanValue', tokenName: 'BooleanValue' },
  259. },
  260. {
  261. ifCondition: 'EnumValue',
  262. expect: { ofType: 'EnumValue', tokenName: 'EnumValue' },
  263. },
  264. {
  265. ifCondition: 'String',
  266. expect: { ofType: 'String', tokenName: 'StringValue' },
  267. },
  268. {
  269. ifCondition: 'BlockString',
  270. expect: { ofType: 'BlockString', tokenName: 'StringValue' },
  271. },
  272. {
  273. ifCondition: 'NullValue',
  274. expect: { ofType: 'NullValue', tokenName: 'NullValue' },
  275. },
  276. {
  277. ifCondition: { token: '[' },
  278. expect: 'ListValue',
  279. },
  280. {
  281. ifCondition: { token: '{' },
  282. expect: 'ObjectValue',
  283. },
  284. ],
  285. },
  286. ConstValue: {
  287. peek: [
  288. {
  289. ifCondition: 'IntValue',
  290. expect: { ofType: 'IntValue' },
  291. },
  292. {
  293. ifCondition: 'FloatValue',
  294. expect: { ofType: 'FloatValue' },
  295. },
  296. {
  297. ifCondition: 'BooleanValue',
  298. expect: 'BooleanValue',
  299. },
  300. {
  301. ifCondition: 'EnumValue',
  302. expect: 'EnumValue',
  303. },
  304. {
  305. ifCondition: 'String',
  306. expect: { ofType: 'String', tokenName: 'StringValue' },
  307. },
  308. {
  309. ifCondition: 'BlockString',
  310. expect: { token: 'BlockString', tokenName: 'StringValue' },
  311. },
  312. {
  313. ifCondition: 'NullValue',
  314. expect: 'NullValue',
  315. },
  316. {
  317. ifCondition: { token: '[' },
  318. expect: 'ConstListValue',
  319. },
  320. {
  321. ifCondition: { token: '{' },
  322. expect: 'ObjectValue',
  323. },
  324. ],
  325. },
  326. IntValue: { token: 'Int' },
  327. FloatValue: { token: 'Float' },
  328. StringValue: {
  329. peek: [
  330. {
  331. ifCondition: { token: 'String' },
  332. expect: { token: 'String', tokenName: 'StringValue' },
  333. },
  334. {
  335. ifCondition: { token: 'BlockString' },
  336. expect: { token: 'BlockString', tokenName: 'StringValue' },
  337. },
  338. ],
  339. },
  340. BooleanValue: {
  341. token: 'Name',
  342. oneOf: ['true', 'false'],
  343. tokenName: 'BooleanValue',
  344. },
  345. NullValue: {
  346. token: 'Name',
  347. ofValue: 'null',
  348. tokenName: 'NullValue',
  349. },
  350. EnumValue: {
  351. token: 'Name',
  352. butNot: { token: 'Name', oneOf: ['null', 'true', 'false'] },
  353. tokenName: 'EnumValue',
  354. },
  355. ListValue: [
  356. { token: '[' },
  357. { listOfType: 'Value', optional: true },
  358. { token: ']' },
  359. ],
  360. ConstListValue: [
  361. { token: '[' },
  362. { listOfType: 'ConstValue', optional: true },
  363. { token: ']' },
  364. ],
  365. ObjectValue: [
  366. { token: '{' },
  367. { listOfType: 'ObjectField', optional: true },
  368. { token: '}' },
  369. ],
  370. ObjectField: [
  371. { token: 'Name', tokenName: 'ObjectFieldName' },
  372. { token: ':' },
  373. { ofType: 'ConstValue' },
  374. ],
  375. Variable: [
  376. { token: '$', tokenName: 'VariableName' },
  377. { token: 'Name', tokenName: 'VariableName' },
  378. ],
  379. VariableDefinitions: [
  380. { token: '(' },
  381. { listOfType: 'VariableDefinition' },
  382. { token: ')' },
  383. ],
  384. VariableDefinition: [
  385. 'Variable',
  386. { token: ':' },
  387. 'Type',
  388. { ofType: 'DefaultValue', optional: true },
  389. ],
  390. DefaultValue: [{ token: '=' }, 'ConstValue'],
  391. TypeName: { token: 'Name', tokenName: 'TypeName', typeName: true },
  392. Type: {
  393. peek: [
  394. {
  395. ifCondition: { token: 'Name' },
  396. expect: ['TypeName', { token: '!', optional: true }],
  397. },
  398. {
  399. ifCondition: { token: '[' },
  400. expect: 'ListType',
  401. },
  402. ],
  403. },
  404. ListType: [
  405. { token: '[' },
  406. { listOfType: 'Type' },
  407. { token: ']' },
  408. { token: '!', optional: true },
  409. ],
  410. Directives: { listOfType: 'Directive' },
  411. Directive: [
  412. { token: '@', tokenName: 'DirectiveName' },
  413. { token: 'Name', tokenName: 'DirectiveName' },
  414. { ofType: 'Arguments', optional: true },
  415. ],
  416. TypeSystemDefinition: [
  417. { ofType: 'Description', optional: true },
  418. {
  419. peek: [
  420. {
  421. ifCondition: {
  422. target: 'Name',
  423. ofValue: 'schema',
  424. },
  425. expect: 'SchemaDefinition',
  426. },
  427. {
  428. ifCondition: {
  429. target: 'Name',
  430. ofValue: 'scalar',
  431. },
  432. expect: 'ScalarTypeDefinition',
  433. },
  434. {
  435. ifCondition: {
  436. target: 'Name',
  437. ofValue: 'type',
  438. },
  439. expect: 'ObjectTypeDefinition',
  440. },
  441. {
  442. ifCondition: {
  443. target: 'Name',
  444. ofValue: 'interface',
  445. },
  446. expect: 'InterfaceTypeDefinition',
  447. },
  448. {
  449. ifCondition: {
  450. target: 'Name',
  451. ofValue: 'union',
  452. },
  453. expect: 'UnionTypeDefinition',
  454. },
  455. {
  456. ifCondition: {
  457. target: 'Name',
  458. ofValue: 'enum',
  459. },
  460. expect: 'EnumTypeDefinition',
  461. },
  462. {
  463. ifCondition: {
  464. target: 'Name',
  465. ofValue: 'input',
  466. },
  467. expect: 'InputObjectTypeDefinition',
  468. },
  469. {
  470. ifCondition: {
  471. target: 'Name',
  472. ofValue: 'directive',
  473. },
  474. expect: 'DirectiveDefinition',
  475. },
  476. ],
  477. },
  478. ],
  479. TypeSystemExtension: {
  480. peek: [
  481. {
  482. ifCondition: {
  483. target: 'Name',
  484. ofValue: 'schema',
  485. },
  486. expect: 'SchemaExtension',
  487. },
  488. {
  489. ifCondition: {
  490. target: 'Name',
  491. ofValue: 'scalar',
  492. },
  493. expect: 'ScalarTypeExtension',
  494. },
  495. {
  496. ifCondition: {
  497. target: 'Name',
  498. ofValue: 'type',
  499. },
  500. expect: 'ObjectTypeExtension',
  501. },
  502. {
  503. ifCondition: {
  504. target: 'Name',
  505. ofValue: 'interface',
  506. },
  507. expect: 'InterfaceTypeExtension',
  508. },
  509. {
  510. ifCondition: {
  511. target: 'Name',
  512. ofValue: 'union',
  513. },
  514. expect: 'UnionTypeExtension',
  515. },
  516. {
  517. ifCondition: {
  518. target: 'Name',
  519. ofValue: 'enum',
  520. },
  521. expect: 'EnumTypeExtension',
  522. },
  523. {
  524. ifCondition: {
  525. target: 'Name',
  526. ofValue: 'input',
  527. },
  528. expect: 'InputObjectTypeExtension',
  529. },
  530. ],
  531. },
  532. SchemaDefinition: [
  533. {
  534. token: 'Name',
  535. ofValue: 'schema',
  536. tokenName: 'SchemaDefinitionKeyword',
  537. },
  538. { ofType: 'Directives', optional: true },
  539. { token: '{' },
  540. { listOfType: 'RootOperationTypeDefinition' },
  541. { token: '}' },
  542. ],
  543. RootOperationTypeDefinition: [
  544. 'OperationType',
  545. { token: ':' },
  546. { token: 'Name', tokenName: 'OperationTypeDefinitionName' },
  547. ],
  548. SchemaExtension: [
  549. { token: 'Name', ofValue: 'extend' },
  550. { token: 'Name', ofValue: 'schema' },
  551. 'Name',
  552. {
  553. peek: [
  554. {
  555. ifCondition: { token: '@' },
  556. expect: [
  557. 'Directives',
  558. {
  559. ofType: [
  560. { token: '{' },
  561. { listOfType: 'RootOperationTypeDefinition' },
  562. { token: '}' },
  563. ],
  564. optional: true,
  565. },
  566. ],
  567. },
  568. {
  569. ifCondition: { token: '{' },
  570. expect: [
  571. { token: '{' },
  572. { listOfType: 'RootOperationTypeDefinition' },
  573. { token: '}' },
  574. ],
  575. },
  576. ],
  577. },
  578. ],
  579. Description: 'StringValue',
  580. ScalarTypeDefinition: [
  581. { ofType: 'Description', optional: true },
  582. {
  583. token: 'Name',
  584. ofValue: 'scalar',
  585. tokenName: 'ScalarDefinitionKeyword',
  586. },
  587. 'TypeName',
  588. { ofType: 'Directives', optional: true },
  589. ],
  590. ScalarTypeExtension: [
  591. {
  592. token: 'Name',
  593. ofValue: 'extend',
  594. tokenName: 'ExtendDefinitionKeyword',
  595. },
  596. {
  597. token: 'Name',
  598. ofValue: 'scalar',
  599. tokenName: 'ScalarDefinitionKeyword',
  600. },
  601. 'TypeName',
  602. 'Directives',
  603. ],
  604. ObjectTypeDefinition: [
  605. { ofType: 'Description', optional: true },
  606. {
  607. token: 'Name',
  608. ofValue: 'type',
  609. tokenName: 'TypeDefinitionKeyword',
  610. },
  611. 'TypeName',
  612. { ofType: 'ImplementsInterfaces', optional: true },
  613. { ofType: 'Directives', optional: true },
  614. { ofType: 'FieldsDefinition', optional: true },
  615. ],
  616. ImplementsInterfaces: [
  617. {
  618. token: 'Name',
  619. ofValue: 'implements',
  620. tokenName: 'ImplementsKeyword',
  621. },
  622. { token: '&', optional: true },
  623. 'TypeName',
  624. {
  625. listOfType: 'ImplementsAdditionalInterfaceName',
  626. optional: true,
  627. },
  628. ],
  629. ImplementsAdditionalInterfaceName: [{ token: '&' }, 'TypeName'],
  630. FieldsDefinition: [
  631. { token: '{' },
  632. { listOfType: 'FieldDefinition' },
  633. { token: '}' },
  634. ],
  635. FieldDefinition: [
  636. { ofType: 'Description', optional: true },
  637. { token: 'Name', tokenName: 'AliasName', definitionName: true },
  638. { ofType: 'ArgumentsDefinition', optional: true },
  639. { token: ':' },
  640. 'Type',
  641. { ofType: 'Directives', optional: true },
  642. ],
  643. ArgumentsDefinition: [
  644. { token: '(' },
  645. { listOfType: 'InputValueDefinition' },
  646. { token: ')' },
  647. ],
  648. InputValueDefinition: [
  649. { ofType: 'Description', optional: true },
  650. { token: 'Name', tokenName: 'ArgumentName' },
  651. { token: ':' },
  652. 'Type',
  653. { ofType: 'DefaultValue', optional: true },
  654. { ofType: 'Directives', optional: true },
  655. ],
  656. ObjectTypeExtension: [
  657. {
  658. token: 'Name',
  659. ofValue: 'extend',
  660. tokenName: 'ExtendDefinitionKeyword',
  661. },
  662. {
  663. token: 'Name',
  664. ofValue: 'type',
  665. tokenName: 'TypeDefinitionKeyword',
  666. },
  667. 'TypeName',
  668. {
  669. peek: [
  670. {
  671. ifCondition: { token: 'Name', ofValue: 'interface' },
  672. expect: [
  673. 'ImplementsInterfaces',
  674. {
  675. peek: [
  676. {
  677. ifCondition: { token: '@' },
  678. expect: [
  679. 'Directives',
  680. { ofType: 'FieldsDefinition', optional: true },
  681. ],
  682. },
  683. {
  684. ifCondition: { token: '{' },
  685. expect: 'FieldsDefinition',
  686. },
  687. ],
  688. optional: true,
  689. },
  690. ],
  691. },
  692. {
  693. ifCondition: { token: '@' },
  694. expect: [
  695. 'Directives',
  696. { ofType: 'FieldsDefinition', optional: true },
  697. ],
  698. },
  699. {
  700. ifCondition: { token: '{' },
  701. expect: 'FieldsDefinition',
  702. },
  703. ],
  704. },
  705. ],
  706. InterfaceTypeDefinition: [
  707. { ofType: 'Description', optional: true },
  708. {
  709. token: 'Name',
  710. ofValue: 'interface',
  711. tokenName: 'InterfaceDefinitionKeyword',
  712. },
  713. 'TypeName',
  714. { ofType: 'Directives', optional: true },
  715. { ofType: 'FieldsDefinition', optional: true },
  716. ],
  717. InterfaceTypeExtension: [
  718. {
  719. token: 'Name',
  720. ofValue: 'extend',
  721. tokenName: 'ExtendDefinitionKeyword',
  722. },
  723. {
  724. token: 'Name',
  725. ofValue: 'interface',
  726. tokenName: 'InterfaceDefinitionKeyword',
  727. },
  728. 'TypeName',
  729. {
  730. peek: [
  731. {
  732. ifCondition: { token: '@' },
  733. expect: [
  734. 'Directives',
  735. { ofType: 'FieldsDefinition', optional: true },
  736. ],
  737. },
  738. {
  739. ifCondition: { token: '{' },
  740. expect: 'FieldsDefinition',
  741. },
  742. ],
  743. },
  744. ],
  745. UnionTypeDefinition: [
  746. { ofType: 'Description', optional: true },
  747. {
  748. token: 'Name',
  749. ofValue: 'union',
  750. tokenName: 'UnionDefinitionKeyword',
  751. },
  752. 'TypeName',
  753. { ofType: 'Directives', optional: true },
  754. { ofType: 'UnionMemberTypes', optional: true },
  755. ],
  756. UnionMemberTypes: [
  757. { token: '=' },
  758. { token: '|', optional: true },
  759. 'Name',
  760. {
  761. listOfType: 'UnionMemberAdditionalTypeName',
  762. optional: true,
  763. },
  764. ],
  765. UnionMemberAdditionalTypeName: [{ token: '|' }, 'TypeName'],
  766. UnionTypeExtension: [
  767. {
  768. token: 'Name',
  769. ofValue: 'extend',
  770. tokenName: 'ExtendDefinitionKeyword',
  771. },
  772. {
  773. token: 'Name',
  774. ofValue: 'union',
  775. tokenName: 'UnionDefinitionKeyword',
  776. },
  777. 'TypeName',
  778. {
  779. peek: [
  780. {
  781. ifCondition: { token: '@' },
  782. expect: [
  783. 'Directives',
  784. { ofType: 'UnionMemberTypes', optional: true },
  785. ],
  786. },
  787. {
  788. ifCondition: { token: '=' },
  789. expect: 'UnionMemberTypes',
  790. },
  791. ],
  792. },
  793. ],
  794. EnumTypeDefinition: [
  795. { ofType: 'Description', optional: true },
  796. {
  797. token: 'Name',
  798. ofValue: 'enum',
  799. tokenName: 'EnumDefinitionKeyword',
  800. },
  801. 'TypeName',
  802. { ofType: 'Directives', optional: true },
  803. { ofType: 'EnumValuesDefinition', optional: true },
  804. ],
  805. EnumValuesDefinition: [
  806. { token: '{' },
  807. { listOfType: 'EnumValueDefinition' },
  808. { token: '}' },
  809. ],
  810. EnumValueDefinition: [
  811. { ofType: 'Description', optional: true },
  812. 'EnumValue',
  813. { ofType: 'Directives', optional: true },
  814. ],
  815. EnumTypeExtension: [
  816. {
  817. token: 'Name',
  818. ofValue: 'extend',
  819. tokenName: 'ExtendDefinitionKeyword',
  820. },
  821. {
  822. token: 'Name',
  823. ofValue: 'enum',
  824. tokenName: 'EnumDefinitionKeyword',
  825. },
  826. 'TypeName',
  827. {
  828. peek: [
  829. {
  830. ifCondition: { token: '@' },
  831. expect: [
  832. 'Directives',
  833. { ofType: 'EnumValuesDefinition', optional: true },
  834. ],
  835. },
  836. {
  837. ifCondition: { token: '{' },
  838. expect: 'EnumValuesDefinition',
  839. },
  840. ],
  841. },
  842. ],
  843. InputObjectTypeDefinition: [
  844. { ofType: 'Description', optional: true },
  845. {
  846. token: 'Name',
  847. ofValue: 'input',
  848. tokenName: 'InputDefinitionKeyword',
  849. },
  850. 'TypeName',
  851. { ofType: 'Directives', optional: true },
  852. { ofType: 'InputFieldsDefinition', optional: true },
  853. ],
  854. InputFieldsDefinition: [
  855. { token: '{' },
  856. { listOfType: 'InputValueDefinition' },
  857. { token: '}' },
  858. ],
  859. InputObjectTypeExtension: [
  860. {
  861. token: 'Name',
  862. ofValue: 'extend',
  863. tokenName: 'ExtendDefinitionKeyword',
  864. },
  865. {
  866. token: 'Name',
  867. ofValue: 'input',
  868. tokenName: 'InputDefinitionKeyword',
  869. },
  870. 'TypeName',
  871. {
  872. peek: [
  873. {
  874. ifCondition: { token: '@' },
  875. expect: [
  876. 'Directives',
  877. { ofType: 'InputFieldsDefinition', optional: true },
  878. ],
  879. },
  880. {
  881. ifCondition: { token: '{' },
  882. expect: 'InputFieldsDefinition',
  883. },
  884. ],
  885. },
  886. ],
  887. DirectiveDefinition: [
  888. { ofType: 'Description', optional: true },
  889. {
  890. token: 'Name',
  891. ofValue: 'directive',
  892. tokenName: 'DirectiveDefinitionKeyword',
  893. },
  894. { token: '@', tokenName: 'DirectiveName' },
  895. { token: 'Name', tokenName: 'DirectiveName' },
  896. { ofType: 'ArgumentsDefinition', optional: true },
  897. { token: 'Name', ofValue: 'on', tokenName: 'OnKeyword' },
  898. 'DirectiveLocations',
  899. ],
  900. DirectiveLocations: [
  901. { token: '|', optional: true },
  902. 'DirectiveLocation',
  903. {
  904. listOfType: 'DirectiveLocationAdditionalName',
  905. optional: true,
  906. },
  907. ],
  908. DirectiveLocationAdditionalName: [{ token: '|' }, 'DirectiveLocation'],
  909. DirectiveLocation: {
  910. peek: [
  911. {
  912. ifCondition: 'ExecutableDirectiveLocation',
  913. expect: 'ExecutableDirectiveLocation',
  914. },
  915. {
  916. ifCondition: 'TypeSystemDirectiveLocation',
  917. expect: 'TypeSystemDirectiveLocation',
  918. },
  919. ],
  920. },
  921. ExecutableDirectiveLocation: {
  922. token: 'Name',
  923. oneOf: [
  924. 'QUERY',
  925. 'MUTATION',
  926. 'SUBSCRIPTION',
  927. 'FIELD',
  928. 'FRAGMENT_DEFINITION',
  929. 'FRAGMENT_SPREAD',
  930. 'INLINE_FRAGMENT',
  931. ],
  932. tokenName: 'EnumValue',
  933. },
  934. TypeSystemDirectiveLocation: {
  935. token: 'Name',
  936. oneOf: [
  937. 'SCHEMA',
  938. 'SCALAR',
  939. 'OBJECT',
  940. 'FIELD_DEFINITION',
  941. 'ARGUMENT_DEFINITION',
  942. 'INTERFACE',
  943. 'UNION',
  944. 'ENUM',
  945. 'ENUM_VALUE',
  946. 'INPUT_OBJECT',
  947. 'INPUT_FIELD_DEFINITION',
  948. ],
  949. tokenName: 'EnumValue',
  950. },
  951. // FIXME: enforce proper typing
  952. }: any);
  953. export default grammar;