0

我正在使用带有 .NET 后端的 GraphQL。我在 .NET 后端有一个如下实体:

 public ulong Id { get; set; }
    public ulong PartnerId { get; set; }
    public uint? OnStockQuantity { get; set; }
    public string ProductNumber { get; set; }
    public string ShortName { get; set; }
    public string LongName { get; set; }
    public string Description { get; set; }
    public int? VATId { get; set; }
    public DateTime? DeletedAt { get; set; }
    public string AdditionalData { get; set; }

    public ICollection<Product2Document> Product2Documents { get; set; }

对于来自 GraphQL 的查询,我使用Product2Documents获得了所需的 Get 结果。但是,问题是我无法从 GraphQL执行Create突变。我没有找到在 ListGraphType 中设置Product2Documents的确切方法。

以下是我在 PostMan 中使用的 post 对象,这绝对可以正常工作,但问题出在 GraphQL 中。

我在这里写下创建请求的 GraphQL 变异查询:

产品类别

public ProductType()
    {
        Field(x => x.Id);
        Field(x => x.OnStockQuantity, nullable: true);
        Field(x => x.ProductNumber, nullable: true);    
        Field(x => x.ShortName, nullable: true);
        Field(x => x.LongName, nullable: true);
        Field(x => x.Description, nullable: true);
        Field(x => x.VATId, nullable: true);
        Field(x => x.AdditionalData, nullable: true);
        Field<ListGraphType<Product2DocumentType>>("product2Documents");
        Field(x => x.DeletedAt, type: typeof(DateTimeGraphType), nullable: true);
        Field(x => x.CreatedDate, type: typeof(DateTimeGraphType), nullable: true);
        Field(x => x.UpdatedDate, type: typeof(DateTimeGraphType), nullable: true);
    }

Product2DocumentType

 public Product2DocumentType()
    {
        Field(x => x.Id, nullable: true);
        Field(x => x.DocumentId, nullable: true);
        Field(x => x.ProductId, nullable: true);
    }

突变

  FieldAsync<ProductType>(
             name: "createProduct",
             arguments: new QueryArguments(
                new QueryArgument<IntGraphType> { Name = "OnStockQuantity" },
                new QueryArgument<StringGraphType> { Name = "ProductNumber" },
                new QueryArgument<StringGraphType> { Name = "ShortName" },
                new QueryArgument<StringGraphType> { Name = "LongName" },
                new QueryArgument<StringGraphType> { Name = "Description" },
                new QueryArgument<IntGraphType> { Name = "VATId" },
                new QueryArgument<StringGraphType> { Name = "AdditionalData" },
                // To DO
                new QueryArgument<ListGraphType<Product2DocumentType>> { Name = "product2Documents" }
             ),
             resolve: async _ =>
             {
                 var result = await productService.Post(new ProductPost()
                 {
                     OnStockQuantity = _.GetArgument<uint?>("onStockQuantity"),
                     ProductNumber = _.GetArgument<string>("productNumber"),
                     ShortName = _.GetArgument<string>("shortName"),
                     LongName = _.GetArgument<string>("longName"),
                     Description = _.GetArgument<string>("description"),
                     VATId = _.GetArgument<int?>("vATId"),
                     AdditionalData = _.GetArgument<string>("additionalData"),
                 }, (_.UserContext as DaveContext).GetHeader());
                 return result?.Data?[0];
             });

这就是我想从下面的 GraphQL 突变中发送的内容。

期待

{
        "onStockQuantity": 20,
        "productNumber": 5,
        "Product2Documents": [
            {"documentId": 111},
            {"documentId": 222}
        ]
        

}

4

0 回答 0