UNPKG

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