Closed bryantserres closed 1 year ago
No this is not currently supported. What would be the use case of having this supported in functions generating mock data?
it could be useful for defaults with mock data generating functions
example:
enum Status {
ONLINE
OFFLINE
}
using graphql-codegen/cli with enumsAsTypes: true
would output:
export type Status = 'ONLINE' | 'OFFLINE';
a mock data generator would be output as something like the following using the schema's enum vs. the generated enum as a string union type which results is TS errors related to a type that is being used as a value:
export const aStatus = (overrides?: Partial < ... >) => {
return {
status: overrides && overrides.hasOwnProperty('status') ? overrides.status : Status.ONLINE,
};
};
desired output would be:
export const aStatus = (overrides?: Partial < ... >) => {
return {
status: overrides && overrides.hasOwnProperty('status') ? overrides.status : 'ONLINE',
};
};
also, willing to put out a PR to add this functionality 🙂
Ah interesting, that makes sense indeed. Feel free to open a PR to add this functionnality, but make sure to add unit tests, the code is not as clean as I would like, but we try to cover all use cases with unit tests
Fixed in #118
may have missed something but is
enumsAsTypes
(https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#enumsastypes) currently supported?