Skip to content

Commit 03e9bc3

Browse files
authored
Merge branch 'ardeois:main' into change-case-for-enum-values
2 parents 0698ce8 + b8d3ad4 commit 03e9bc3

File tree

5 files changed

+1305
-1127
lines changed

5 files changed

+1305
-1127
lines changed

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
# v2.1.2 (Fri Feb 18 2022)
2+
3+
#### 🐛 Bug Fix
4+
5+
- fix: wrong type generated when terminateCircularRelationships is true [#70](https://github.com/ardeois/graphql-codegen-typescript-mock-data/pull/70) ([@BenStirrup](https://github.com/BenStirrup) [@ardeois](https://github.com/ardeois))
6+
7+
#### Authors: 2
8+
9+
- Benjamin Stirrup ([@BenStirrup](https://github.com/BenStirrup))
10+
- Corentin Ardeois ([@ardeois](https://github.com/ardeois))
11+
12+
---
13+
14+
# v2.1.1 (Fri Feb 18 2022)
15+
16+
#### ⚠️ Pushed to `main`
17+
18+
- feat: dependency update ([@ardeois](https://github.com/ardeois))
19+
20+
#### Authors: 1
21+
22+
- Corentin Ardeois ([@ardeois](https://github.com/ardeois))
23+
24+
---
25+
26+
# v2.1.0 (Fri Feb 18 2022)
27+
28+
#### 🚀 Enhancement
29+
30+
- fix: #69 [#71](https://github.com/ardeois/graphql-codegen-typescript-mock-data/pull/71) ([@bokuweb](https://github.com/bokuweb) [@ardeois](https://github.com/ardeois))
31+
32+
#### Authors: 2
33+
34+
- bokuweb ([@bokuweb](https://github.com/bokuweb))
35+
- Corentin Ardeois ([@ardeois](https://github.com/ardeois))
36+
37+
---
38+
139
# v2.0.0 (Thu Nov 04 2021)
240

341
#### 💥 Breaking Change

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-codegen-typescript-mock-data",
3-
"version": "2.0.0",
3+
"version": "2.1.2",
44
"description": "GraphQL Codegen plugin for building mock data",
55
"main": "dist/commonjs/index.js",
66
"module": "dist/esnext/index.js",
@@ -22,31 +22,31 @@
2222
"fakes"
2323
],
2424
"dependencies": {
25-
"@graphql-codegen/plugin-helpers": "^1.17.9",
25+
"@graphql-codegen/plugin-helpers": "^2.4.1",
2626
"casual": "^1.6.2",
2727
"indefinite": "^2.4.1",
2828
"pascal-case": "^3.1.1",
2929
"sentence-case": "^3.0.3",
3030
"upper-case": "^2.0.1"
3131
},
3232
"peerDependencies": {
33-
"graphql": "^14.6.0 || ^15.0.0"
33+
"graphql": "^14.6.0 || ^15.0.0 || ^16.0.0"
3434
},
3535
"devDependencies": {
36-
"@auto-it/conventional-commits": "^10.32.1",
36+
"@auto-it/conventional-commits": "^10.32.6",
3737
"@graphql-codegen/testing": "^1.17.7",
3838
"@types/faker": "^5.5.9",
3939
"@types/jest": "^27.0.2",
4040
"@typescript-eslint/eslint-plugin": "^5.1.0",
4141
"@typescript-eslint/parser": "^5.1.0",
42-
"auto": "^10.32.1",
42+
"auto": "^10.32.6",
4343
"eslint": "8.0.1",
4444
"eslint-config-landr": "0.7.0",
4545
"eslint-config-prettier": "^8.3.0",
4646
"eslint-plugin-import": "^2.25.2",
4747
"eslint-plugin-jest": "^25.2.2",
4848
"eslint-plugin-prettier": "^4.0.0",
49-
"graphql": "^15.6.1",
49+
"graphql": "^16.3.0",
5050
"husky": "^7.0.0",
5151
"jest": "^27.3.1",
5252
"lint-staged": "^11.2.3",

src/index.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ASTKindToNode, NamedTypeNode, parse, printSchema, TypeNode, visit, VisitFn } from 'graphql';
1+
import { ASTKindToNode, NamedTypeNode, parse, printSchema, TypeNode } from 'graphql';
22
import casual from 'casual';
3-
import { PluginFunction } from '@graphql-codegen/plugin-helpers';
3+
import { PluginFunction, oldVisit } from '@graphql-codegen/plugin-helpers';
44
import { pascalCase } from 'pascal-case';
55
import { upperCase } from 'upper-case';
66
import { sentenceCase } from 'sentence-case';
@@ -181,7 +181,7 @@ const getNamedType = (opts: Options<NamedTypeNode>): string | number | boolean =
181181
}
182182
}
183183
if (opts.terminateCircularRelationships) {
184-
return `relationshipsToOmit.has('${name}') ? {} as ${name} : ${toMockName(
184+
return `relationshipsToOmit.has('${casedName}') ? {} as ${casedName} : ${toMockName(
185185
name,
186186
casedName,
187187
opts.prefix,
@@ -212,6 +212,8 @@ const generateMockValue = (opts: Options): string | number | boolean => {
212212
});
213213
return `[${value}]`;
214214
}
215+
default:
216+
throw new Error('unreached');
215217
}
216218
};
217219

@@ -323,6 +325,23 @@ interface TypeItem {
323325
types?: readonly NamedTypeNode[];
324326
}
325327

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+
326345
type VisitorType = { [K in keyof ASTKindToNode]?: VisitFn<ASTKindToNode[keyof ASTKindToNode], ASTKindToNode[K]> };
327346

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

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

tests/__snapshots__/typescript-mock-data.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ export const aUser = (overrides?: Partial<User>, relationshipsToOmit: Set<string
19811981
status: overrides && overrides.hasOwnProperty('status') ? overrides.status! : Status.Online,
19821982
customStatus: overrides && overrides.hasOwnProperty('customStatus') ? overrides.customStatus! : AbcStatus.HasXyzStatus,
19831983
scalarValue: overrides && overrides.hasOwnProperty('scalarValue') ? overrides.scalarValue! : 'neque',
1984-
camelCaseThing: overrides && overrides.hasOwnProperty('camelCaseThing') ? overrides.camelCaseThing! : relationshipsToOmit.has('camelCaseThing') ? {} as camelCaseThing : aCamelCaseThing({}, relationshipsToOmit),
1984+
camelCaseThing: overrides && overrides.hasOwnProperty('camelCaseThing') ? overrides.camelCaseThing! : relationshipsToOmit.has('CamelCaseThing') ? {} as CamelCaseThing : aCamelCaseThing({}, relationshipsToOmit),
19851985
unionThing: overrides && overrides.hasOwnProperty('unionThing') ? overrides.unionThing! : relationshipsToOmit.has('Avatar') ? {} as Avatar : anAvatar({}, relationshipsToOmit),
19861986
prefixedEnum: overrides && overrides.hasOwnProperty('prefixedEnum') ? overrides.prefixedEnum! : PrefixedEnum.PrefixedValue,
19871987
};
@@ -2036,7 +2036,7 @@ export const aQuery = (overrides?: Partial<Query>, relationshipsToOmit: Set<stri
20362036
relationshipsToOmit.add('Query');
20372037
return {
20382038
user: overrides && overrides.hasOwnProperty('user') ? overrides.user! : relationshipsToOmit.has('User') ? {} as User : aUser({}, relationshipsToOmit),
2039-
prefixed_query: overrides && overrides.hasOwnProperty('prefixed_query') ? overrides.prefixed_query! : relationshipsToOmit.has('Prefixed_Response') ? {} as Prefixed_Response : aPrefixedResponse({}, relationshipsToOmit),
2039+
prefixed_query: overrides && overrides.hasOwnProperty('prefixed_query') ? overrides.prefixed_query! : relationshipsToOmit.has('PrefixedResponse') ? {} as PrefixedResponse : aPrefixedResponse({}, relationshipsToOmit),
20402040
};
20412041
};
20422042
"

0 commit comments

Comments
 (0)