How do I pass two parameters to GraphQLHttpClient in c#?

Viewed 1267

I am having a problem similar to this. I have updated my GraphQLHttpClient and now I need to supply an extra parameter, solution give is:

GraphQLHttpClient gql = new GraphQLHttpClient(o => {
o.EndPoint = _config["API:Endpoint"];
o.JsonSerializer = new NewtonsoftJsonSerializer();
});

but this tells me: Error CS1729 'GraphQLHttpClient' does not contain a constructor that takes 1 arguments I have also tried:

using Newtonsoft.Json
GraphQLHttpClient gql = new GraphQLHttpClient(_options.Url, new Newtonsoft.Json.JsonSerializer());

which gives Error CS1503 Argument 2: cannot convert from 'Newtonsoft.Json.JsonSerializer' to 'GraphQL.Client.Abstractions.Websocket.IGraphQLWebsocketJsonSerializer'

I know very little c# so I'd be grateful for any pointers.

1 Answers

Your first solution correctly tries to use NewtonsoftJsonSerializer which is an implementation of IGraphQLWebsocketJsonSerializer to use Newtonsoft.

Your second correctly uses a constructor which takes it, but you have changed it to be Newtonsoft.Json.JsonSerializer which is not an implementation of IGraphQLWebsocketJsonSerializer.

What you want is the second one, but with the right type of IGraphQLWebsocketJsonSerializer:

GraphQLHttpClient gql = new GraphQLHttpClient(_options.Url, new NewtonsoftJsonSerializer());
Related