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

Global types with enum values #81

Closed
chrbala opened this issue May 10, 2020 · 4 comments · Fixed by #144
Closed

Global types with enum values #81

chrbala opened this issue May 10, 2020 · 4 comments · Fixed by #144
Assignees
Labels
bug Something isn't working duplicate This issue or pull request already exists
Milestone

Comments

@chrbala
Copy link

chrbala commented May 10, 2020

Because of the update to export only global types, enum values break. That is, because enum values pass through the types to the underlying Gatbsy compilation process, the Gatsby compilation process doesn't know how to handle the global types. Example below.

GraphQL definition

enum MyEnum {
  SOME_VALUE
  OTHER_VALUE
}

This gets transformed to the following in gatsby-types.ts

enum MyEnum {
  SOME_VALUE = 'SOME_VALUE',
  OTHER_VALUE = 'OTHER_VALUE',
}

Typescript then allows the following usage:

const acceptMyEnum = (value: GatsbyTypes.MyEnum) => value == GatsbyTypes.MyEnum.SOME_VALUE ? "something" : "something else";

But the actual Gatsby build fails where GatbsyTypes is needed in the runtime because it can't find GatsbyTypes with an error of "GatsbyTypes" is not defined. Is it possible to emit both the global types and the older importable types? Otherwise, is there better solution to this?

@cometkim
Copy link
Owner

Duplicates #78

These enum values will be changed into an internal type union after #79 is merged.

@cometkim cometkim added the duplicate This issue or pull request already exists label May 10, 2020
@cometkim cometkim mentioned this issue May 10, 2020
2 tasks
@orblazer
Copy link

Hello @cometkim, this bug is still present.
In the release 2.2.0 that PR #80 is missing, probably fail.

@cometkim
Copy link
Owner

Oh no 😢 @orblazer you right. Thank you for notifying it.

image

@cometkim cometkim reopened this Oct 31, 2020
@cometkim cometkim added this to the v3 milestone Oct 31, 2020
@cometkim cometkim self-assigned this Oct 31, 2020
@cometkim cometkim added the bug Something isn't working label Oct 31, 2020
cometkim added a commit that referenced this issue Dec 14, 2020
@cometkim
Copy link
Owner

Published at v2.2.2

#135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants