-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Allow special characters in an enum #12200
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
Allow special characters in an enum #12200
Conversation
Codecov Report
@@ Coverage Diff @@
## master #12200 +/- ##
==========================================
+ Coverage 47.61% 47.62% +0.01%
==========================================
Files 228 228
Lines 8515 8517 +2
Branches 1901 1901
==========================================
+ Hits 4054 4056 +2
Misses 3666 3666
Partials 795 795
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| // Scalars | ||
| else if (isStrapiScalar(attribute)) { | ||
| if (isStrapiScalar(attribute)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there the specific reason you remove codes in this file? It reverts the fix in #12005
master
this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good eye :)
The input stays as an enum but the output is put as a string so special characters could be returned. I put an example in the PR description. Do you see a problem with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I just found that special characters are not supported in GraphQL specs..
http://spec.graphql.org/October2021/#note-46408
Names in GraphQL are limited to the Latin ASCII subset of SourceCharacter in order to support interoperation with as many other systems as possible.
I think there will be more advantages of using the string type than using the enum type :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, thank you :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was just about to ask if this is a good idea since we just had an issue that GraphQL was returning strings for enums.... 🤔 It would be nice to put this issue to bed honestly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iicdii fixed this in #12005
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's trade-off. It lose some benefit of autogenerating api documentation If you force to enum to be a string. Otherwise, you can't use special characters because of GraphQL spec.
I think the way to satisfy both sides is to give the user an option to use special characters or not. If user checked to use special chracters, enum types are shown as string. Otherwise, enum types are shown as enum, and the validation should be applied not to allow special characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, it seems a reasonable proposition to put a config option for that. What do you think @alexandrebodin @Convly and @derrickmehaffy ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, though I would advise by default we shouldn't allow it.
packages/core/content-type-builder/admin/src/utils/toGraphQLName.js
Outdated
Show resolved
Hide resolved
261c5af to
2730f62
Compare
|
After discussing internally, the field will be a graphql enum for both input and output. The pain point to not have special characters in the enum in the response will be handled in the future with a new type that would look like enum with a key/value system. |
packages/core/content-type-builder/admin/src/components/FormModal/attributes/types.js
Outdated
Show resolved
Hide resolved
Indeed, I think this the better way going forward, enum are a special format type that's designed to be read by multiple types of languages: https://en.wikipedia.org/wiki/Enumerated_type There are usually a lot of restrictions on the format of enumerations depending on the language but restricting chars is a common one. |
|
I have been testing the PR but I get an issue with graphQL now I think. When doing a query I get the normalized value in the response but I can only filter with the non-normalized value. I was expecting the 2 to be the same? |
6ac247a to
96e41eb
Compare



Fix #11703
Allow special characters in an enum.
REST: Nothing special
GraphQL: The enum input uses the normalized format (ex: if your enum value is
démocratiethen your GraphQL input should bedemocratie). The enum output will correctly bedémocratie).EDIT: after discussing it, the output will finally also be
democratie