parser.d.ts 2.7 KB

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