Description
Hi folks,
I am trying to generating mocks using this package. Below is my configs. But, I am not getting proper mocks being generated for Union types. Can anyone please guide here? Thank you!
Config:
//*****************************************************//
mocks.ts:
plugins:
- typescript
- typescript-resolvers
- typescript-mock-data
config:
typeNames: keep
typesFile: './schema-types.ts'
addTypename: true
prefix: 'mock'
listElementCount: 3
mockVariables: true
enumPrefix: false
resolvers: Resolvers
useTypeImports: true
terminateCircularRelationships: true
typeNamesMapping:
ProListSection: ProlistHeaderSection
scalars:
Text: faker.lorem.paragraph()
Date: faker.date.recent().toISOString()
URL: faker.internet.url()
ClientKey: faker.string.alphanumeric(10)
ClientID: faker.string.uuid()
Token: faker.string.alphanumeric(32)
Component: faker.string.alpha(10)
Time: faker.date.recent().toISOString()
EventType: faker.string.alpha(10)
EmptyType: faker.string.alpha(10)
Datetime: faker.date.recent().toISOString()
Upload: faker.string.alpha(10)
SerializedProtobuf: faker.string.alphanumeric(20)
Base64: faker.string.alphanumeric(64)
String: faker.string.alpha(30)
Int: faker.number.int(100)
Float: faker.number.float(100)
Boolean: faker.datatype.boolean()
ID: faker.string.uuid()
//*****************************************************//
Graphql:
//*****************************************************//
export type ABC = A | B | C;
export interface A {
__typename: 'A';
a: string;
xyz: string;
}export interface B {
__typename: 'B';
b: string;
xyz: string;
}export interface C {
__typename: 'C';
c: string;
xyz: string;
}
//*****************************************************//
Current generated mocks:
//*****************************************************//
export const mockABC = (overrides): ABC => {
return {
__typename: 'ABC',
xyz: overrides && overrides.hasOwnProperty('xyz') ? overrides.xyz! : faker.lorem.paragraph(),
}
}
//*****************************************************//
Expected mocks:
//*****************************************************//
export const mockA = (overrides): A => {
return {
__typename: 'A',
a: overrides && overrides.hasOwnProperty('a') ? overrides.a! : faker.lorem.paragraph(),
xyz: overrides && overrides.hasOwnProperty('xyz') ? overrides.xyz! : faker.lorem.paragraph(),
}
}export const mockB = (overrides): B => {
return {
__typename: 'B',
b: overrides && overrides.hasOwnProperty('b') ? overrides.b! : faker.lorem.paragraph(),
xyz: overrides && overrides.hasOwnProperty('xyz') ? overrides.xyz! : faker.lorem.paragraph(),
}
}export const mockC = (overrides): C => {
return {
__typename: 'C',
c: overrides && overrides.hasOwnProperty('c') ? overrides.c! : faker.lorem.paragraph(),
xyz: overrides && overrides.hasOwnProperty('xyz') ? overrides.xyz! : faker.lorem.paragraph(),
}
}
//*****************************************************//