在 Amplify/Appsync 中定义预计算列的正确方法

问题描述

我正在使用 Next.js 和 amplify add api 开发应用程序。在 schema.graphql 中,有以下实体:

type Quotation @model {
    id: ID!
    name: String!
    jobs: [Job]
}

type Job @model {
    id: ID!
    name: String!
    cost: Float!
    revenue: Float!
}

有了这两个实体,我想实现两件事(这是模型情况,实际用例显然更复杂)-计算工作利润(收入-成本)和计算报价利润(总和所有工作利润)。

在 NET Core 中,就像定义以下 DTO 并在 automapper 中映射它们一样简单:

public class QuotationDto 
{
   public Guid Id { get; set; }
   public string Name { get; set; }
   public ICollection<JobDto> Jobs { get; set; }
   public double Profit => Jobs.Sum(e => e.Profit);
}

public class JobDto
{
   public Guid Id { get; set; }
   public string Name { get; set; }
   public double Cost { get; set; }
   public double Revenue { get; set; }
   public double Profit => Revenue - Cost;
}

在 amplify/appsync 工作流程中实现这一目标的正确方法是什么,最好是在不离开 VS Code 的情况下?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)