Typescript 在Amplify/Appsync中定义预计算列的正确方法
我正在使用Next.js和Typescript 在Amplify/Appsync中定义预计算列的正确方法,typescript,graphql,aws-amplify,aws-appsync,aws-amplify-sdk-js,Typescript,Graphql,Aws Amplify,Aws Appsync,Aws Amplify Sdk Js,我正在使用Next.js和放大添加api开发应用程序。在schema.graphql中,有以下实体: type Quotation @model { id: ID! name: String! jobs: [Job] } type Job @model { id: ID! name: String! cost: Float! revenue: Float! } 有了这两个实体,我想实现两件事(这是模型情况,实际用例显然更复杂)——计算工
放大添加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;
}
public class QuotationDto
{
公共Guid Id{get;set;}
公共字符串名称{get;set;}
公共ICollection作业{get;set;}
公共双利润=>Jobs.Sum(e=>e.price);
}
公务舱
{
公共Guid Id{get;set;}
公共字符串名称{get;set;}
公共双成本{get;set;}
公共双收入{get;set;}
公共双利润=>收入-成本;
}
在amplify/appsync工作流中实现这一点的正确方法是什么,最好不留下VS代码