grammar.d.ts 22 KB

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