graphql-codegen-typescript-mock-data
graphql-codegen-typescript-mock-data copied to clipboard
Won't respect typesPrefix: "I"
Hi, our settings file goes like this
overwrite: true
schema: "http://localhost:3000/graphql"
generates:
constants/mocks/index.ts:
plugins:
- typescript-mock-data:
typesFile: "../../types"
enumValues: upper-case#upperCase
typeNames: change-case-all#pascalCase
typesPrefix: "I"
prefix: "Mock"
addTypename: true
generateLibrary: faker
terminateCircularRelationships: true
scalars:
Date:
generator: date.past
arguments: 10
ID:
generator: database.mongodbObjectId
fieldGeneration:
_all:
email: internet.email
bio: lorem.paragraph
firstName: name.firstName
lastName: name.lastName
fullName: name.fullName
title: company.name
File:
key: undefined
FileURLs:
original: image.abstract
FileStream:
url: undefined
and our types generator goes like this
overwrite: true
schema: "http://localhost:3000/graphql"
generates:
types/index.ts:
plugins:
- typescript
- typescript-operations
config:
declarationKind:
type: "interface"
input: "interface"
typesPrefix: "I"
enumPrefix: false
enumsAsConst: true
maybeValue: T
namingConvention:
enumValues: keep
types/apollo.ts:
plugins:
- fragment-matcher
config:
apolloClientVersion: 3
This was working until today but today, generator generates like below;
emails:
overrides && overrides.hasOwnProperty("emails")
? overrides.emails!
: [
relationshipsToOmit.has("Email")
? ({} as Email)
: MockEmail({}, relationshipsToOmit),
],
but it should be
emails:
overrides && overrides.hasOwnProperty("emails")
? overrides.emails!
: [
relationshipsToOmit.has("IEmail")
? ({} as IEmail)
: MockEmail({}, relationshipsToOmit),
],
btw this is correctly generated;
export const MockEmail = (
overrides?: Partial<IEmail>,
_relationshipsToOmit: Set<string> = new Set(),
): { __typename: "Email" } & IEmail => {
const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit);
relationshipsToOmit.add("Email");
return {
__typename: "Email",
address:
overrides && overrides.hasOwnProperty("address") ? overrides.address! : "quaerat",
primary:
overrides && overrides.hasOwnProperty("primary") ? overrides.primary! : true,
verified:
overrides && overrides.hasOwnProperty("verified") ? overrides.verified! : true,
};
};
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If anyone interested, I'm using this workaround until this is fixed graphql-codegen --config ./codegen-mocks.yml && perl -pi -w -e 's/{} as /{} as I/g;' ./constants/mocks/index.ts && prettier --write ./constants/mocks
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.