UNPKG

4.07 kBTypeScriptView Raw
1import { NormalizedScalarsMap } from './types';
2import { DeclarationBlockConfig } from './utils';
3import { GraphQLSchema, FragmentDefinitionNode, OperationDefinitionNode } from 'graphql';
4import { SelectionSetToObject } from './selection-set-to-object';
5import { OperationVariablesToObject } from './variables-to-object';
6import { BaseVisitor } from './base-visitor';
7import { ParsedTypesConfig, RawTypesConfig } from './base-types-visitor';
8export interface ParsedDocumentsConfig extends ParsedTypesConfig {
9 addTypename: boolean;
10 preResolveTypes: boolean;
11 globalNamespace: boolean;
12 operationResultSuffix: string;
13 dedupeOperationSuffix: boolean;
14 omitOperationSuffix: boolean;
15 namespacedImportName: string | null;
16 exportFragmentSpreadSubTypes: boolean;
17 skipTypeNameForRoot: boolean;
18 experimentalFragmentVariables: boolean;
19}
20export interface RawDocumentsConfig extends RawTypesConfig {
21 /**
22 * @default false
23 * @description Avoid using `Pick` and resolve the actual primitive type of all selection set.
24 *
25 * @exampleMarkdown
26 * ```yml
27 * plugins
28 * config:
29 * preResolveTypes: true
30 * ```
31 */
32 preResolveTypes?: boolean;
33 /**
34 * @default false
35 * @description Avoid adding `__typename` for root types. This is ignored when a selection explictly specifies `__typename`.
36 *
37 * @exampleMarkdown
38 * ```yml
39 * plugins
40 * config:
41 * skipTypeNameForRoot: true
42 * ```
43 */
44 skipTypeNameForRoot?: boolean;
45 /**
46 * @default false
47 * @description Puts all generated code under `global` namespace. Useful for Stencil integration.
48 *
49 * @exampleMarkdown
50 * ```yml
51 * plugins
52 * config:
53 * globalNamespace: true
54 * ```
55 */
56 globalNamespace?: boolean;
57 /**
58 * @default ""
59 * @description Adds a suffix to generated operation result type names
60 */
61 operationResultSuffix?: string;
62 /**
63 * @default false
64 * @description Set this configuration to `true` if you wish to make sure to remove duplicate operation name suffix.
65 */
66 dedupeOperationSuffix?: boolean;
67 /**
68 * @default false
69 * @description Set this configuration to `true` if you wish to disable auto add suffix of operation name, like `Query`, `Mutation`, `Subscription`, `Fragment`.
70 */
71 omitOperationSuffix?: boolean;
72 /**
73 * @default false
74 * @description If set to true, it will export the sub-types created in order to make it easier to access fields declared under fragment spread.
75 */
76 exportFragmentSpreadSubTypes?: boolean;
77 /**
78 * @default false
79 * @description If set to true, it will enable support for parsing variables on fragments.
80 */
81 experimentalFragmentVariables?: boolean;
82 /**
83 * @ignore
84 */
85 namespacedImportName?: string;
86}
87export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig = RawDocumentsConfig, TPluginConfig extends ParsedDocumentsConfig = ParsedDocumentsConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
88 protected _schema: GraphQLSchema;
89 protected _unnamedCounter: number;
90 protected _variablesTransfomer: OperationVariablesToObject;
91 protected _selectionSetToObject: SelectionSetToObject;
92 protected _globalDeclarations: Set<string>;
93 constructor(rawConfig: TRawConfig, additionalConfig: TPluginConfig, _schema: GraphQLSchema, defaultScalars?: NormalizedScalarsMap);
94 getGlobalDeclarations(noExport?: boolean): string[];
95 setSelectionSetHandler(handler: SelectionSetToObject): void;
96 setDeclarationBlockConfig(config: DeclarationBlockConfig): void;
97 setVariablesTransformer(variablesTransfomer: OperationVariablesToObject): void;
98 get schema(): GraphQLSchema;
99 get addTypename(): boolean;
100 private handleAnonymousOperation;
101 FragmentDefinition(node: FragmentDefinitionNode): string;
102 protected applyVariablesWrapper(variablesBlock: string): string;
103 OperationDefinition(node: OperationDefinitionNode): string;
104}