Husqvik / GraphQlClientGenerator

GraphQL C# client generator
MIT License
213 stars 49 forks source link

Fix parameterized queries with enum arguments #130

Open gao-artur opened 1 year ago

gao-artur commented 1 year ago

Consider the following schema

type Device {
  enabled: Toggle
  name: String
}

enum Toggle {
  DISABLED
  ENABLED
}

type Query {
  devices(isEnabled: Toggle): [Device!]!
}

And the following query

var queryBuilder = new QueryQueryBuilder()
    .WithParameter(new GraphQlQueryParameter<Toggle?>("isEnabled"))
    .WithDevices(new DeviceQueryBuilder()
            .WithName()
            .WithEnabled(),
        new GraphQlQueryParameter<Toggle?>("isEnabled"));

This throws exception

System.ArgumentException: value required (Parameter 'graphQlTypeName')
    at SampleServer.GeneratedGraphqlClient.QueryBuilderParameter`1.EnsureGraphQlTypeName(String graphQlTypeName) in C:\SampleServer.Tests\GeneratedGraphqlClient.cs:line 454
   at SampleServer.GeneratedGraphqlClient.QueryBuilderParameter`1..ctor(String name, String graphQlTypeName) in C:\SampleServer.Tests\GeneratedGraphqlClient.cs:line 438
   at SampleServer.GeneratedGraphqlClient.GraphQlQueryParameter`1..ctor(String name, String graphQlTypeName) in C:\SampleServer.Tests\GeneratedGraphqlClient.cs:line 472
   at SampleServer.Tests.Tests.Test() in C:\SampleServer.Tests\Tests.cs:line 15