本文介绍了创建GraphQLHttpClient时GraphQLClient错误:IGraphQLWebsocketJsonSerializer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GraphQL版本2.1.0,我无法创建对象:GraphQLHttpClient.

Using GraphQL version 2.1.0, I can't create the object: GraphQLHttpClient.

我立即收到以下错误:

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred. (no implementation of "GraphQL.Client.Abstractions.Websocket.IGraphQLWebsocketJsonSerializer" found)
  Source=System.Private.CoreLib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at (...)Program.Main(String[] args) in (..)\Program.cs:line 22

  This exception was originally thrown at this call stack:
    GraphQL.Client.Abstractions.GraphQLJsonSerializerExtensions.EnsureAssigned<TSerializerInterface>(TSerializerInterface)
    GraphQL.Client.Http.GraphQLHttpClient.GraphQLHttpClient(GraphQL.Client.Http.GraphQLHttpClientOptions, System.Net.Http.HttpClient)
    GraphQL.Client.Http.GraphQLHttpClient.GraphQLHttpClient(GraphQL.Client.Http.GraphQLHttpClientOptions)
    GraphQL.Client.Http.GraphQLHttpClient.GraphQLHttpClient(System.Action<GraphQL.Client.Http.GraphQLHttpClientOptions>)
    GraphQL.Client.Http.GraphQLHttpClient.GraphQLHttpClient(System.Uri)
    GraphQL.Client.Http.GraphQLHttpClient.GraphQLHttpClient(string)
    (...)Program.MainAsync() in Program.cs

Inner Exception 1:
InvalidOperationException: no implementation of "GraphQL.Client.Abstractions.Websocket.IGraphQLWebsocketJsonSerializer" found

代码:

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;
using System.Text;
using GraphQL;
using GraphQL.Client;
using System.Threading.Tasks;
using System.Collections.Generic;
using GraphQL.Client.Abstractions;
using GraphQL.Client.Http;

namespace OW_1
{
    class Program
    {

        static void Main(string[] args)
        {
            MainAsync().Wait();
        }

        static async Task MainAsync()
        {
            var graphQLClient = new GraphQLHttpClient("X");

        }
    }
}

它与GraphQLHttpClient一起崩溃.以前,我使用过1.0.3(带有:GraphQLClient类),并且可以正常工作.

It's crashing on line with GraphQLHttpClient.Before, I've used 1.0.3 (with: GraphQLClient class) and it worked.

推荐答案

只要人们对这个问题有所了解,就会知道最终将起作用的原因:

Just so if people land on this question, knows what finally will works:

        var graphQLOptions = new GraphQLHttpClientOptions
        {
            EndPoint = new Uri("https://your_endpoint.com/output", UriKind.Absolute),
        };
       var graphQLClient = new GraphQLHttpClient(graphQLOptions, new NewtonsoftJsonSerializer());

       var msg = new GraphQLRequest
        {
            Query = "query { yourSampleQuery { yourData} }"
        };
       var graphQLResponse = await graphQLClient.SendQueryAsync<dynamic>(msg).ConfigureAwait(false);

仅需考虑的一点是var graphQLClient应该是静态的,因此我们不会在每次调用时对其进行更新.

Just a point to consider is var graphQLClient should be static, so we do not new it up on each call.

这篇关于创建GraphQLHttpClient时GraphQLClient错误:IGraphQLWebsocketJsonSerializer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 19:21