|
1 |
| -import { ASTKindToNode, NamedTypeNode, parse, printSchema, TypeNode, visit, VisitFn } from 'graphql'; |
| 1 | +import { ASTKindToNode, NamedTypeNode, parse, printSchema, TypeNode } from 'graphql'; |
2 | 2 | import casual from 'casual';
|
3 |
| -import { PluginFunction } from '@graphql-codegen/plugin-helpers'; |
| 3 | +import { PluginFunction, oldVisit } from '@graphql-codegen/plugin-helpers'; |
4 | 4 | import { pascalCase } from 'pascal-case';
|
5 | 5 | import { upperCase } from 'upper-case';
|
6 | 6 | import { sentenceCase } from 'sentence-case';
|
@@ -212,6 +212,8 @@ const generateMockValue = (opts: Options): string | number | boolean => {
|
212 | 212 | });
|
213 | 213 | return `[${value}]`;
|
214 | 214 | }
|
| 215 | + default: |
| 216 | + throw new Error('unreached'); |
215 | 217 | }
|
216 | 218 | };
|
217 | 219 |
|
@@ -323,6 +325,23 @@ interface TypeItem {
|
323 | 325 | types?: readonly NamedTypeNode[];
|
324 | 326 | }
|
325 | 327 |
|
| 328 | +type VisitFn<TAnyNode, TVisitedNode = TAnyNode> = ( |
| 329 | + /** The current node being visiting. */ |
| 330 | + node: TVisitedNode, |
| 331 | + /** The index or key to this node from the parent node or Array. */ |
| 332 | + key: string | number | undefined, |
| 333 | + /** The parent immediately above this node, which may be an Array. */ |
| 334 | + parent: TAnyNode | ReadonlyArray<TAnyNode> | undefined, |
| 335 | + /** The key path to get to this node from the root node. */ |
| 336 | + path: ReadonlyArray<string | number>, |
| 337 | + /** |
| 338 | + * All nodes and Arrays visited before reaching parent of this node. |
| 339 | + * These correspond to array indices in `path`. |
| 340 | + * Note: ancestors includes arrays which contain the parent of visited node. |
| 341 | + */ |
| 342 | + ancestors: ReadonlyArray<TAnyNode | ReadonlyArray<TAnyNode>>, |
| 343 | +) => any; |
| 344 | + |
326 | 345 | type VisitorType = { [K in keyof ASTKindToNode]?: VisitFn<ASTKindToNode[keyof ASTKindToNode], ASTKindToNode[K]> };
|
327 | 346 |
|
328 | 347 | // This plugin was generated with the help of ast explorer.
|
@@ -480,7 +499,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
|
480 | 499 | },
|
481 | 500 | };
|
482 | 501 |
|
483 |
| - const result = visit(astNode, { leave: visitor }); |
| 502 | + const result = oldVisit(astNode, { leave: visitor }); |
484 | 503 | const definitions = result.definitions.filter((definition: any) => !!definition);
|
485 | 504 | const typesFile = config.typesFile ? config.typesFile.replace(/\.[\w]+$/, '') : null;
|
486 | 505 |
|
|
0 commit comments