-
Notifications
You must be signed in to change notification settings - Fork 2k
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
enum coercion in mutation argument from string does not work... #122
Comments
As of 2cf2f4c this should now be working as specified. |
[deleted] Sorry for the false alarm-- was still pulling in the old version. |
Actually, I am still seeing this issue with the latest code:
And a new one (invalid JSON because 'blue' isn't quoted or in scope):
|
Your test here looks the same as 2cf2f4c#diff-a333d8645ed867ad7e82181baa05ad14R135 which is currently passing. Could you draft a test case that includes your definition files? That would help me understand if there is a bug that I'm not seeing here, or I can help you understand if there is an issue with your code that I could improve error messaging for. |
Oh, I see the problem. In my query declaration, I'm specifying the actual GraphQLEnumType ('ColorType' in your case) for the Attempting to coerce the supplied value into the expected value was what I expected. Otherwise, there would be a lot of unnecessary, repeated boilerplate for each query wanting to take advantage of this coercion. Here's my mutation definition (please pardon the ClojureScript syntax) ["Color" is a GraphQLEnumType]:
|
P.S. from my reading of the code yesterday, the only problem seemed to be that |
I'm curious what the definition for |
I'm not sure I follow this. Validation is a static-time pass that happens before a query is executed. Variable values ("blue" in this case) are only introduced at Execution time. |
Oh, sorry. I was confusing with the other bug-- i.e., allowing coercion in arguments as well as parameters. I just figured the two were related. |
Gotcha. That one should be covered. |
Here's the descriptor for my
Sorry for the collossal waste of your time! And thanks for your help! |
No problem, this is actually really valuable information. I will add assertion messages that enums are properly constructed. That could have saved you a lot of time, I'm sure! |
I'm sorry to report that I'm still getting the error. My 'Color' enum is now described by:
And this is the request:
[EDIT: oops, sorry. Please ignore my analysis of your code previously pasted here]. Since you do seem to have the cases to cover this, I will keep searching in my codes for the bug. |
Actually, there is a difference between our test cases here: mine involves a mutation and yours is a plain query. Here's the descriptor for my mutation:
i.e., this object is placed on the |
That shouldn't change the test case - the code for checking variable values happens before determining the type of operation. |
Ahh, cool. Good to know. |
This asserts that Enums have properly configured values. This also asserts that isTypeOf and resolveType are functions, if provided. Finally, this changes the signature of EnumType.getValues() to return an array instead of an Object map, since every single use case was calling Object.keys. This fixes #122
Also relevant: #1324 So this is the most relevant issue I could find... I am having a similar issue where using the actual Enum Constant value (not a string) in GraphiQL coerces my Enum key to it's specified value correctly. When sending JSON instead, however, I don't get a GraphQL schema error (although in GraphiQL I do) but the input value is not coerced: export const StatusType = new GraphQLEnumType({
name: "enumStatusType",
values: {
"ACTIVE": {
value: "Active"
},
"PAUSED": {
value: "Paused"
},
"STOPPED": {
value: "Stopped"
},
"PENDING": {
value: "Pending"
},
"DRAFT": {
value: "Draft"
}
}
}); This will coerce ACTIVE -> "Active" (in GraphiQL): mutation {
bulkEdit(
mutations: [
{
_kind_: "user"
_id_: "123"
_operation_: "edit"
status: ACTIVE
}
]
)
} This will not: {
"query": "...",
"variables": {
"mutations": {
...
"status": "ACTIVE"
}
}
} The main difference is one uses variables over JSON and therefore MUST use a string ("ACTIVE" in this case), while the other does not. The JSON version will not coerce "ACTIVE" to "Active" for usage in the backend, though it does for reads ("Active" -> "ACTIVE"). I hope this makes sense and thank you. |
... however coercion from int does (arguably coercion from string is more useful than coercion from int).
Schema:
Client:
Server:
Bad request:
The text was updated successfully, but these errors were encountered: