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