Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums wrongly transpiled #9

Open
newLoki opened this issue Mar 3, 2022 · 1 comment
Open

Enums wrongly transpiled #9

newLoki opened this issue Mar 3, 2022 · 1 comment

Comments

@newLoki
Copy link
Contributor

newLoki commented Mar 3, 2022

Describe the bug
Enums defined in the graphql schema are transpiled into typescript type definitions.
For the purpose of mapping responses from a connected shop into one of those enums the types are not feasible at all.
An example is the MeasurementUnit enum, that will get transpiled to

export type MeasurementUnit =
  | 'ACRE'
  | 'ARES'

this isn't very usable when hydrating the article.salesUnit.name field from the response of a connected shop, as this will always be a String, which isn't allowed as MeasurementUnit.

Proposal is to either find a way that enums from the graphql schema are transpiled to enums in typescript or always add the String to those enums, which makes them useless.

@alexanderkraus
Copy link
Member

alexanderkraus commented Mar 10, 2022

Although generating TypeScript enums for GraphQL enums would work with GraphQL Code Generator, the issue is that TypeScript Enums eventually have to be transpiled to JavaScript. They are not "types" like interface or type. The purpose of generating TypeScript definitions for the GraphQL schema is actually meant to help using the schema, but not to force developers to use TypeScript in any way.

If the underlying system already provides values that can be passed through to objects without having to be transformed, one could still provide type hints:

const unitName = '...'; // from underlying system

const myBaseUnit: BaseUnit = {
  id: 'ITEM',
  name: unitName as MeasurementUnit,
  interval: 1,
  minQuantity: 1,
  standardQuantity: 1,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants