Skip to content

Commit f50d8f9

Browse files
authored
Merge branch 'main' into feat/add-default-nullable-to-null-config
2 parents 1e149be + 2ecc1b2 commit f50d8f9

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# v3.4.2 (Wed Apr 19 2023)
2+
3+
#### 🐛 Bug Fix
4+
5+
- allow `listElementCount` to be 0 in config [#129](https://github.com/ardeois/graphql-codegen-typescript-mock-data/pull/129) ([@gurschitz](https://github.com/gurschitz))
6+
7+
#### Authors: 1
8+
9+
- Gerald Urschitz ([@gurschitz](https://github.com/gurschitz))
10+
11+
---
12+
113
# v3.4.1 (Thu Apr 13 2023)
214

315
#### 🐛 Bug Fix

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-codegen-typescript-mock-data",
3-
"version": "3.4.1",
3+
"version": "3.4.2",
44
"description": "GraphQL Codegen plugin for building mock data",
55
"main": "dist/commonjs/index.js",
66
"module": "dist/esnext/index.js",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
567567
const enumValuesConvention = config.enumValues || 'change-case-all#pascalCase';
568568
const typeNamesConvention = config.typeNames || 'change-case-all#pascalCase';
569569
const transformUnderscore = config.transformUnderscore ?? true;
570-
const listElementCount = config.listElementCount > 0 ? config.listElementCount : 1;
570+
const listElementCount = Math.max(0, config.listElementCount ?? 1);
571571
const dynamicValues = !!config.dynamicValues;
572572
const generateLibrary = config.generateLibrary || 'casual';
573573
const enumsAsTypes = config.enumsAsTypes ?? false;

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,85 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
26332633
"
26342634
`;
26352635

2636+
exports[`should generate no list elements when listElementCount is 0 1`] = `
2637+
"import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, ListType, UpdateUserInput, Mutation, Query, AbcStatus, Status, PrefixedEnum } from './types/graphql';
2638+
2639+
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
2640+
return {
2641+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '0550ff93-dd31-49b4-8c38-ff1cb68bdc38',
2642+
url: overrides && overrides.hasOwnProperty('url') ? overrides.url! : 'aliquid',
2643+
};
2644+
};
2645+
2646+
export const aUser = (overrides?: Partial<User>): User => {
2647+
return {
2648+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'a5756f00-41a6-422a-8a7d-d13ee6a63750',
2649+
creationDate: overrides && overrides.hasOwnProperty('creationDate') ? overrides.creationDate! : '1970-01-09T16:33:21.532Z',
2650+
login: overrides && overrides.hasOwnProperty('login') ? overrides.login! : 'libero',
2651+
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
2652+
status: overrides && overrides.hasOwnProperty('status') ? overrides.status! : Status.Online,
2653+
customStatus: overrides && overrides.hasOwnProperty('customStatus') ? overrides.customStatus! : AbcStatus.HasXyzStatus,
2654+
scalarValue: overrides && overrides.hasOwnProperty('scalarValue') ? overrides.scalarValue! : 'neque',
2655+
camelCaseThing: overrides && overrides.hasOwnProperty('camelCaseThing') ? overrides.camelCaseThing! : aCamelCaseThing(),
2656+
unionThing: overrides && overrides.hasOwnProperty('unionThing') ? overrides.unionThing! : anAvatar(),
2657+
prefixedEnum: overrides && overrides.hasOwnProperty('prefixedEnum') ? overrides.prefixedEnum! : PrefixedEnum.PrefixedValue,
2658+
};
2659+
};
2660+
2661+
export const aWithAvatar = (overrides?: Partial<WithAvatar>): WithAvatar => {
2662+
return {
2663+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '89f515e7-31e0-461d-a230-c4c7f4dafc5c',
2664+
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
2665+
};
2666+
};
2667+
2668+
export const aCamelCaseThing = (overrides?: Partial<CamelCaseThing>): CamelCaseThing => {
2669+
return {
2670+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '345b9cf9-00fa-4974-800f-aeee5ee7fd42',
2671+
};
2672+
};
2673+
2674+
export const aPrefixedResponse = (overrides?: Partial<PrefixedResponse>): PrefixedResponse => {
2675+
return {
2676+
ping: overrides && overrides.hasOwnProperty('ping') ? overrides.ping! : 'sunt',
2677+
};
2678+
};
2679+
2680+
export const anAbcType = (overrides?: Partial<AbcType>): AbcType => {
2681+
return {
2682+
abc: overrides && overrides.hasOwnProperty('abc') ? overrides.abc! : 'sit',
2683+
};
2684+
};
2685+
2686+
export const aListType = (overrides?: Partial<ListType>): ListType => {
2687+
return {
2688+
stringList: overrides && overrides.hasOwnProperty('stringList') ? overrides.stringList! : [],
2689+
};
2690+
};
2691+
2692+
export const anUpdateUserInput = (overrides?: Partial<UpdateUserInput>): UpdateUserInput => {
2693+
return {
2694+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '1d6a9360-c92b-4660-8e5f-04155047bddc',
2695+
login: overrides && overrides.hasOwnProperty('login') ? overrides.login! : 'qui',
2696+
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
2697+
};
2698+
};
2699+
2700+
export const aMutation = (overrides?: Partial<Mutation>): Mutation => {
2701+
return {
2702+
updateUser: overrides && overrides.hasOwnProperty('updateUser') ? overrides.updateUser! : aUser(),
2703+
};
2704+
};
2705+
2706+
export const aQuery = (overrides?: Partial<Query>): Query => {
2707+
return {
2708+
user: overrides && overrides.hasOwnProperty('user') ? overrides.user! : aUser(),
2709+
prefixed_query: overrides && overrides.hasOwnProperty('prefixed_query') ? overrides.prefixed_query! : aPrefixedResponse(),
2710+
};
2711+
};
2712+
"
2713+
`;
2714+
26362715
exports[`should generate single list element 1`] = `
26372716
"import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, ListType, UpdateUserInput, Mutation, Query, AbcStatus, Status, PrefixedEnum } from './types/graphql';
26382717

tests/typescript-mock-data.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,19 @@ it('should generate multiple list elements', async () => {
482482
expect(result).toMatchSnapshot();
483483
});
484484

485+
it('should generate no list elements when listElementCount is 0', async () => {
486+
const result = await plugin(testSchema, [], {
487+
typesFile: './types/graphql.ts',
488+
listElementCount: 0,
489+
});
490+
491+
expect(result).toBeDefined();
492+
expect(result).toContain(
493+
"stringList: overrides && overrides.hasOwnProperty('stringList') ? overrides.stringList! : []",
494+
);
495+
expect(result).toMatchSnapshot();
496+
});
497+
485498
it('should generate dynamic values in mocks', async () => {
486499
const result = await plugin(testSchema, [], { dynamicValues: true });
487500

0 commit comments

Comments
 (0)