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 in subscription 'query' #77
Comments
When executing the operation you should use the enum in the GraphQLQueryArgument. For example: var operation = await graphQLSubscriptionClient.ExecuteOperation(new GraphQLQueryArgument("fromSrc", RdSrc.SB)); This should generate the correct query. |
Hmmm, it's making something 'weird'....
|
You should put the name of the enumtype in GraphQL. You can find this name using introspection for example using GraphQL Playground or GraphiQL. It could for example be RdSrc. |
Ok (can't believe I hadn't tried that!). Because of the IsRequired, it seems I need "RdSrc!". I'm still finding it difficult to tie up both ends though. The above sends 0 as the arg value, which my server rejects since it isn't SB or XB. I can get the textual form of the enum, but that is then a string and so (obviously) gets quoted by GraphQLQueryArgument.... |
This may or may not be a similar thing, but I'm also having trouble doing an introspection ValidateGraphQLType on a query which also takes this enum as an argument: |
Hello, You can use EnumMember (Newtonsoft.Json).
Would you create a issue on the other issue with the introspection? This is clearly a bug |
Still trying to work through that suggestion, but isn't it going to still have the problem of giving something of type string, and end up quoted? i.e.
whereas an enum param needs to be
I suspect some additional classes/types would be needed to support this? |
I have found out the problem is the default way Newtonsoft.Json serializes enums. I have created some testcode which shows how it's possible to override the default behaviour. |
I'm not surprised that its an awkward case - in any programming language an enum is just used as-is, as in GraphQL. But through any intermediate serializing like JSON/XML/etc, they tend to quote the 'values' |
You are completely correct. According to the spec it should be "values are represented as unquoted names". This should therefore be handled in this library possible by providing a default custom JsonConverter. |
I have found the problem in |
It should now be fixed for all inlined arguments. I'm not sure if it should also be updated for variables would you check if your server has the same problem for not inlined arguments?
|
I've tried both query and subscription, with inline both true and false - all four cases are being generated correctly, and accepted by my server. |
I can add a string argument to a subscription:
Gives a query:
Trouble is, the argument actually needs to be an enum:
for query
Is this possible..?
The text was updated successfully, but these errors were encountered: