Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# type:Byte无法有效强制为GraphQL类型_C#_Asp.net Core 2.0_Graphql Dotnet - Fatal编程技术网

C# type:Byte无法有效强制为GraphQL类型

C# type:Byte无法有效强制为GraphQL类型,c#,asp.net-core-2.0,graphql-dotnet,C#,Asp.net Core 2.0,Graphql Dotnet,下面是我用来获取ByteArrayContent类型的代码: public class ImageDTO : APIResult { public byte[] ImageData { get; set; } public string ImageFormat { get; set; } public ImageDTO() { ImageData =

下面是我用来获取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);
        }

        );
    }
}
公共类ImageDTO:APIResult
{
公共字节[]图像数据
{
得到;
设置
}
公共字符串图像格式
{
得到;
设置
}
公众形象
{
ImageData=新字节[]{};
}
}
公共类ImageType:ObjectGraphType,IGraphQLType
{
公共图像类型()
{
字段(img=>img.ImageData);
字段(img=>img.ImageFormat);
}
}
公共类ImageResolver:解析程序,IIImageResolver
{
私有只读ICommonService\u commonService;
公共映像解析程序(ICommonService commonService)
{
_commonService=commonService;
}
公共无效解析(GraphQLQuery GraphQLQuery)
{
字段(“imageresponse”,参数:newQueryArguments(newQueryArguments{Name=“imageId”,Description=“项目id”}),解析:context=>
{
var imageId=context.GetArgument(“imageId”);
var imageResult=_commonService.GetImage(imageId);
如果(imageResult==null)
{
返回NotFoundError(imageId);
}
返回响应(imageResult);
}
);
}
}
在执行上述代码时,我得到了下面提到的错误。 无法有效地将type:Byte强制为GraphQL类型\r\n GraphQL类型的参数名称:type\r\n

从链接:,可以看到ByteGraphType是受支持的。我正在使用版本为2.3.0的GraphQL.net nuget包。所以我认为它应该支持ByteGraphType


请您在这里帮助我了解如何解决此问题。

而不是此行=>
字段(img=>img.ImageData)

您可以使用这个=>
字段(img=>img.ImageData,type:typeof(IdGraphType))