c# - 创建 GraphQLHttpClient 时出现 GraphQLClient 错误:IGraphQLWebsocketJsonSerializer
问题描述
使用 GraphQL 版本 2.1.0,我无法创建对象: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 类)并且它有效。
解决方案
就这样,如果人们遇到这个问题,就知道最终会发生什么:
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 应该是静态的,因此我们不会在每次调用时都对其进行更新。
推荐阅读
- php - Mysql 用计数器更新
- typescript - 无法删除 EventListener
- sql - 转换为十进制时“转换为 int 时出错”
- oracle - 在 Oracle 中将 CLOB 写入文件
- typescript - 关闭特定文件命名空间下的所有类型
- acumatica - 在更新合同价格中覆盖流程委托
- typescript - Ionic 3 在选项卡上使用带有 DeepLinkMetadataType 的 IonPage - 摆脱 tab-0
- vba - 网页抓取数据目的地
- sql - SQL Server SSRS 多个查找值
- google-analytics - 如何在 Google Analytics(分析)仪表板小部件中仅显示来自特定来源的流量