c# - 类型:字节不能被有效地强制转换为 GraphQL 类型
问题描述
这是我用来获取 ByteArrayContent 类型的代码:
public class ImageDTO : APIResult
{
public byte[] ImageData
{
get;
set;
}
public string ImageFormat
{
get;
set;
}
public ImageDTO()
{
ImageData = new byte[]{};
}
}
public class ImageType : ObjectGraphType<ImageDTO>, IGraphQLType
{
public ImageType()
{
Field(img => img.ImageData);
Field(img => img.ImageFormat);
}
}
public class ImageResolver : Resolver, IImageResolver
{
private readonly ICommonService _commonService;
public ImageResolver(ICommonService commonService)
{
_commonService = commonService;
}
public void Resolve(GraphQLQuery graphQLQuery)
{
graphQLQuery.Field<ResponseGraphType<ImageType>>("imageresponse", arguments: new QueryArguments(new QueryArgument<NonNullGraphType<StringGraphType>>{Name = "imageId", Description = "id of the project"}), resolve: context =>
{
var imageId = context.GetArgument<string>("imageId");
var imageResult = _commonService.GetImage(imageId);
if (imageResult == null)
{
return NotFoundError(imageId);
}
return Response(imageResult);
}
);
}
}
在执行上面的代码时,我得到了下面提到的错误。类型: Byte 无法有效地强制转换为 GraphQL 类型\r\n参数名称: type\r\n at Type GraphQL。
从链接: https ://github.com/graphql-dotnet/graphql-dotnet/issues/458 ,提到支持ByteGraphType。我正在使用带有 version:2.3.0 的 GraphQL.net nuget 包。所以我相信它应该支持ByteGraphType。
你能帮我看看如何解决这个问题。
解决方案
而不是这一行=>Field(img => img.ImageData);
你可以用这个=>Field(img => img.ImageData, type: typeof(IdGraphType));
推荐阅读
- python-3.x - 如何选择目录(对话框)并在 GUI 上打印选定的目录
- ios - 更新 MapView 引脚位置
- java - 为什么设置火花上下文时出现此错误?
- postgresql - SpringBoot-使用PostgreSQL的多个参数的单值
- javascript - 页面重新加载成功消息php
- java - “.count”在可分页查询中的 spring jpa-named-queries.properties 文件中不起作用
- javascript - 无法更改默认的 nuxt favicon
- python - 如何修改给定的代码以使最终列表仅包含每个字母的单个副本?
- javascript - 如何定义背景滑块的背景以及如何修复它?
- c++ - libcurl 无法正确下载图像文件