Code Monkey home page Code Monkey logo

Comments (13)

chelliwell avatar chelliwell commented on August 19, 2024 1

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.

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 19, 2024

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.

from sahb.graphqlclient.

chelliwell avatar chelliwell commented on August 19, 2024

Hmmm, it's making something 'weird'....
What should I put in the argumentType?

[GraphQLArguments("src", 
    "String",    // <- ??
    "fromSrc", IsRequired = true)]

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 19, 2024

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.

from sahb.graphqlclient.

chelliwell avatar chelliwell commented on August 19, 2024

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....
Although the [Apollo] server docs suggest the enums can have alternative values, I've not got it to accept 0 or "XB" - and in any case that would kinda ignore the use of nicely typed enums?

from sahb.graphqlclient.

chelliwell avatar chelliwell commented on August 19, 2024

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:
"Argument at QryRdByEmitter has a invalid type. Expected is , actual is RdSrc!."

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 19, 2024

Hello,

You can use EnumMember (Newtonsoft.Json).

public enum RdSrc
{
   [EnumMember(Value = "SB")]
   SB,
   [EnumMember(Value = "XB")]
   XB
}

Would you create a issue on the other issue with the introspection? This is clearly a bug

from sahb.graphqlclient.

chelliwell avatar chelliwell commented on August 19, 2024

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.

  subscription subRd{subRd(src:"SB"){src record}}

whereas an enum param needs to be

  subscription subRd{subRd(src:SB){src record}}

I suspect some additional classes/types would be needed to support this?

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 19, 2024

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.

from sahb.graphqlclient.

chelliwell avatar chelliwell commented on August 19, 2024

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'

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 19, 2024

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.

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 19, 2024

I have found the problem in GraphQLQueryGeneratorFromFields. Currently it uses JsonConvert to serilize the value at line 246. This should be handled in a better way.

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 19, 2024

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?

[GraphQLArguments("src", "RdSrc!", "fromSrc", inlineArgument: false, isRequired: true)]

from sahb.graphqlclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.