Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: clean up enum handling #27

Open
julrich opened this issue Aug 29, 2021 · 0 comments
Open

fix: clean up enum handling #27

julrich opened this issue Aug 29, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request gatsby minor Increment the minor version when merged netlify-cms

Comments

@julrich
Copy link
Member

julrich commented Aug 29, 2021

Right now we're jumping through some hoops to get GraphQL- / TypeScript-safe enum values. Those are not safe by default, as used in our JSON schema (e.g. 16:9, or just simply 1).

We use the following code to make them safe, but it's destructive in nature:
https://github.com/kickstartDS/kickstartDS-schema-toolkit/blob/master/jsonschema2graphql/src/graphqlSafeEnumKey.ts
https://github.com/kickstartDS/kickstartDS-schema-toolkit/blob/master/jsonschema2netlifycms/src/safeEnumKey.ts

As in: you can't deterministically convert values back to their original form, once they are made safe. This is why different properties (like ratio or pattern) need to be handled explicitly here, to reconstruct the needed format. As properties can be customized from a project-level (e.g. pattern already is an individualization for kickstartDS/design-system) we can't have custom handling per property here. At least in the long run!

Another difference is the handling of - vs _. Should be consistent, and need no extra handling while converting.

Also see the TODOs here: https://github.com/kickstartDS/gatsby-theme-kickstartDS/blob/master/gatsby-theme-kickstartds/src/components/KickstartDSPageComponent.tsx#L47-L52

@julrich julrich added enhancement New feature or request minor Increment the minor version when merged netlify-cms gatsby labels Aug 29, 2021
@julrich julrich self-assigned this Aug 29, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request gatsby minor Increment the minor version when merged netlify-cms
Projects
None yet
Development

No branches or pull requests

1 participant