mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

review function sanitizeEnumValue() #640

Closed wwmoraes closed 4 years ago

wwmoraes commented 5 years ago

As per PR #637, the function sanitizeEnumValue() does not comply with the GraphQL documentation:

I didn't found any references on the docs for why number/numeric-started string values need an underscore prefix.

mickhansen commented 5 years ago

https://github.com/mickhansen/graphql-sequelize/pull/502

wwmoraes commented 5 years ago

502

Great! Now I can play again with numeric enum values 🥇

mickhansen commented 5 years ago

@wwmoraes Huh? I was mostly referring to the PR that introduced this issue.

wwmoraes commented 5 years ago

@wwmoraes Huh? I was mostly referring to the PR that introduced this issue.

Oh, my bad. The PR's title is misleading.

wwmoraes commented 5 years ago

Ok so just documenting here before any coding: the PR #502 does state that GraphQL enum types "only support ASCII alphanumeric characters, digits and underscores with leading non-digit" which is right, but it doesn't mention that, in GraphQL, there's no enum value: the name is the value itself.

Naming convention (first/second/latest spec [and all in between]):

Name :       */[_A-Za-z][_0-9A-Za-z]/**

Enum values (first/second/latest spec):

Even though JS doesn't have an enum type, solutions like Object.freeze()'ing a key-value objects (being the values strings, numbers or even better, Symbol()) simulate the same enums saw in most languages. Thus, graphql-sequelize should transcript only the enum "name" to GraphQL, making the bridge between the name and value in sequelize queries.

mickhansen commented 5 years ago

@wwmoraes Mind working on a PR? Then we can discuss the changes and cut it as a major

wwmoraes commented 5 years ago

@mickhansen sure thing!

stale[bot] commented 4 years ago

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.