我有我的Checkout
班
export class Checkout {
totalValue: number
subTotalValue: number
shippingCost: number
lineItems: [LineItem] | []
constructor(
totalValue: number,
subTotalValue: number,
shippingCost: number,
lineItems: [LineItem] | []
) {
this.totalValue = totalValue
this.subTotalValue = subTotalValue
this.shippingCost = shippingCost
this.lineItems = lineItems
}
}
在我的typeDefs
export const typeDefs = gql`
extend type Query {
isLoggedIn: Boolean!
checkout: Checkout
}
extend type Checkout {
totalValue: Int
subTotalValue: Int
shippingCost: Int
lineItems: [LineItem]
}
我想要做的是能够构建该TS类并将其设置为阿波罗的本地状态:
cache.writeData({
data: {
isLoggedIn: !!token,
checkout: new Checkout(0, 0, 15, []),
},
})
这是正确的方法吗?