parser.d.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { Source } from './source';
  2. import { TypeNode, ValueNode, DocumentNode } from './ast';
  3. /**
  4. * Configuration options to control parser behavior
  5. */
  6. export interface ParseOptions {
  7. /**
  8. * By default, the parser creates AST nodes that know the location
  9. * in the source that they correspond to. This configuration flag
  10. * disables that behavior for performance or testing.
  11. */
  12. noLocation?: boolean;
  13. /**
  14. * If enabled, the parser will parse empty fields sets in the Schema
  15. * Definition Language. Otherwise, the parser will follow the current
  16. * specification.
  17. *
  18. * This option is provided to ease adoption of the final SDL specification
  19. * and will be removed in v16.
  20. */
  21. allowLegacySDLEmptyFields?: boolean;
  22. /**
  23. * If enabled, the parser will parse implemented interfaces with no `&`
  24. * character between each interface. Otherwise, the parser will follow the
  25. * current specification.
  26. *
  27. * This option is provided to ease adoption of the final SDL specification
  28. * and will be removed in v16.
  29. */
  30. allowLegacySDLImplementsInterfaces?: boolean;
  31. /**
  32. * EXPERIMENTAL:
  33. *
  34. * If enabled, the parser will understand and parse variable definitions
  35. * contained in a fragment definition. They'll be represented in the
  36. * `variableDefinitions` field of the FragmentDefinitionNode.
  37. *
  38. * The syntax is identical to normal, query-defined variables. For example:
  39. *
  40. * fragment A($var: Boolean = false) on T {
  41. * ...
  42. * }
  43. *
  44. * Note: this feature is experimental and may change or be removed in the
  45. * future.
  46. */
  47. experimentalFragmentVariables?: boolean;
  48. }
  49. /**
  50. * Given a GraphQL source, parses it into a Document.
  51. * Throws GraphQLError if a syntax error is encountered.
  52. */
  53. export function parse(
  54. source: string | Source,
  55. options?: ParseOptions,
  56. ): DocumentNode;
  57. /**
  58. * Given a string containing a GraphQL value, parse the AST for that value.
  59. * Throws GraphQLError if a syntax error is encountered.
  60. *
  61. * This is useful within tools that operate upon GraphQL Values directly and
  62. * in isolation of complete GraphQL documents.
  63. */
  64. export function parseValue(
  65. source: string | Source,
  66. options?: ParseOptions,
  67. ): ValueNode;
  68. /**
  69. * Given a string containing a GraphQL Type (ex. `[Int!]`), parse the AST for
  70. * that type.
  71. * Throws GraphQLError if a syntax error is encountered.
  72. *
  73. * This is useful within tools that operate upon GraphQL Types directly and
  74. * in isolation of complete GraphQL documents.
  75. *
  76. * Consider providing the results to the utility function: typeFromAST().
  77. */
  78. export function parseType(
  79. source: string | Source,
  80. options?: ParseOptions,
  81. ): TypeNode;