Skip to content

fix: #69 #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
"fakes"
],
"dependencies": {
"@graphql-codegen/plugin-helpers": "^1.17.9",
"@graphql-codegen/plugin-helpers": "^2.4.1",
"casual": "^1.6.2",
"indefinite": "^2.4.1",
"pascal-case": "^3.1.1",
"sentence-case": "^3.0.3",
"upper-case": "^2.0.1"
},
"peerDependencies": {
"graphql": "^14.6.0 || ^15.0.0"
"graphql": "^14.6.0 || ^15.0.0 || ^16.0.0"
},
"devDependencies": {
"@auto-it/conventional-commits": "^10.32.1",
Expand All @@ -46,7 +46,7 @@
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jest": "^25.2.2",
"eslint-plugin-prettier": "^4.0.0",
"graphql": "^15.6.1",
"graphql": "^16.3.0",
"husky": "^7.0.0",
"jest": "^27.3.1",
"lint-staged": "^11.2.3",
Expand Down
25 changes: 22 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ASTKindToNode, NamedTypeNode, parse, printSchema, TypeNode, visit, VisitFn } from 'graphql';
import { ASTKindToNode, NamedTypeNode, parse, printSchema, TypeNode } from 'graphql';
import casual from 'casual';
import { PluginFunction } from '@graphql-codegen/plugin-helpers';
import { PluginFunction, oldVisit } from '@graphql-codegen/plugin-helpers';
import { pascalCase } from 'pascal-case';
import { upperCase } from 'upper-case';
import { sentenceCase } from 'sentence-case';
Expand Down Expand Up @@ -212,6 +212,8 @@ const generateMockValue = (opts: Options): string | number | boolean => {
});
return `[${value}]`;
}
default:
throw new Error('unreached');
}
};

Expand Down Expand Up @@ -323,6 +325,23 @@ interface TypeItem {
types?: readonly NamedTypeNode[];
}

type VisitFn<TAnyNode, TVisitedNode = TAnyNode> = (
/** The current node being visiting. */
node: TVisitedNode,
/** The index or key to this node from the parent node or Array. */
key: string | number | undefined,
/** The parent immediately above this node, which may be an Array. */
parent: TAnyNode | ReadonlyArray<TAnyNode> | undefined,
/** The key path to get to this node from the root node. */
path: ReadonlyArray<string | number>,
/**
* All nodes and Arrays visited before reaching parent of this node.
* These correspond to array indices in `path`.
* Note: ancestors includes arrays which contain the parent of visited node.
*/
ancestors: ReadonlyArray<TAnyNode | ReadonlyArray<TAnyNode>>,
) => any;

type VisitorType = { [K in keyof ASTKindToNode]?: VisitFn<ASTKindToNode[keyof ASTKindToNode], ASTKindToNode[K]> };

// This plugin was generated with the help of ast explorer.
Expand Down Expand Up @@ -480,7 +499,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
},
};

const result = visit(astNode, { leave: visitor });
const result = oldVisit(astNode, { leave: visitor });
const definitions = result.definitions.filter((definition: any) => !!definition);
const typesFile = config.typesFile ? config.typesFile.replace(/\.[\w]+$/, '') : null;

Expand Down
Loading