UNPKG

3.85 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}
19export interface RawDocumentsConfig extends RawTypesConfig {
20 /**
21 * @default false
22 * @description Avoid using `Pick` and resolve the actual primitive type of all selection set.
23 *
24 * @exampleMarkdown
25 * ```yml
26 * plugins
27 * config:
28 * preResolveTypes: true
29 * ```
30 */
31 preResolveTypes?: boolean;
32 /**
33 * @default false
34 * @description Avoid adding `__typename` for root types. This is ignored when a selection explictly specifies `__typename`.
35 *
36 * @exampleMarkdown
37 * ```yml
38 * plugins
39 * config:
40 * skipTypeNameForRoot: true
41 * ```
42 */
43 skipTypeNameForRoot?: boolean;
44 /**
45 * @default false
46 * @description Puts all generated code under `global` namespace. Useful for Stencil integration.
47 *
48 * @exampleMarkdown
49 * ```yml
50 * plugins
51 * config:
52 * globalNamespace: true
53 * ```
54 */
55 globalNamespace?: boolean;
56 /**
57 * @default ""
58 * @description Adds a suffix to generated operation result type names
59 */
60 operationResultSuffix?: string;
61 /**
62 * @default false
63 * @description Set this configuration to `true` if you wish to make sure to remove duplicate operation name suffix.
64 */
65 dedupeOperationSuffix?: boolean;
66 /**
67 * @default false
68 * @description Set this configuration to `true` if you wish to disable auto add suffix of operation name, like `Query`, `Mutation`, `Subscription`, `Fragment`.
69 */
70 omitOperationSuffix?: boolean;
71 /**
72 * @default false
73 * @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.
74 */
75 exportFragmentSpreadSubTypes?: boolean;
76 /**
77 * @ignore
78 */
79 namespacedImportName?: string;
80}
81export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig = RawDocumentsConfig, TPluginConfig extends ParsedDocumentsConfig = ParsedDocumentsConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
82 protected _schema: GraphQLSchema;
83 protected _unnamedCounter: number;
84 protected _variablesTransfomer: OperationVariablesToObject;
85 protected _selectionSetToObject: SelectionSetToObject;
86 protected _globalDeclarations: Set<string>;
87 constructor(rawConfig: TRawConfig, additionalConfig: TPluginConfig, _schema: GraphQLSchema, defaultScalars?: NormalizedScalarsMap);
88 getGlobalDeclarations(noExport?: boolean): string[];
89 setSelectionSetHandler(handler: SelectionSetToObject): void;
90 setDeclarationBlockConfig(config: DeclarationBlockConfig): void;
91 setVariablesTransformer(variablesTransfomer: OperationVariablesToObject): void;
92 get schema(): GraphQLSchema;
93 get addTypename(): boolean;
94 private handleAnonymousOperation;
95 FragmentDefinition(node: FragmentDefinitionNode): string;
96 protected applyVariablesWrapper(variablesBlock: string): string;
97 OperationDefinition(node: OperationDefinitionNode): string;
98}