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