5

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.

schoon
  • 2,858
  • 3
  • 46
  • 78

1 Answers1

5

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());
Jamiec
  • 133,658
  • 13
  • 134
  • 193
  • Thank you, but that gives me `Error CS0234 The type or namespace name 'NewtonsoftJsonSerializer' does not exist in the namespace` how do I get that one? – schoon Jul 05 '20 at 08:36
  • I had to get nuget package: `GraphQL.Client.Serializer.Newtonsoft`. – schoon Jul 06 '20 at 08:01
  • @schoon yep, I was just about to update this answer with exactly that. Well done! – Jamiec Jul 06 '20 at 08:06