【问题标题】:AWS-CDK Appsync Codefirst input typesAWS-CDK Appsync Codefirst 输入类型
【发布时间】:2021-05-08 19:40:02
【问题描述】:

为了避免数据结构的重复,我想在这样的输入类型上重用类型定义

export const DeviceStatus = new ObjectType('DeviceStatus', {
    definition: {
        time: timestamp,
        firmwareVersion: string
    },
});

export const DeviceStatusInput = new InputType('DeviceStatusInput', {
    definition: {
        tenantId: id_required,
        deviceId: id_required,
        // Reuse of DeviceStatus Field definition
        status: DeviceStatus.attribute()
    }
});

没有错误,因为DeviceStatus.attribute() 的返回类型很好,这适用于ObjectType 继承。

从我的角度来看,这应该可行,但是部署会导致令人讨厌的“创建架构的内部错误”错误。

当然,我可以将整个定义移动到一个对象中并重用它,但这似乎很奇怪。对于 CodeFirst 方法,有什么好的解决方案

【问题讨论】:

    标签: code-first aws-appsync aws-cdk


    【解决方案1】:

    input type 中引用object type 似乎无效。

    推荐查看Can you make a graphql type both an input and output type?

    你能做的最好的可能是创建一些方便的方法,从单一定义中创建对象和输入类型。

    【讨论】:

    • 即使与 aws-cdk 没有直接关系的难度也可能是正确的答案(链接中采用的方法)。但在这种情况下,如果 typescript API 确实拒绝那里的类型会很有帮助
    猜你喜欢
    • 2021-04-14
    • 2021-06-29
    • 2019-04-22
    • 2021-01-07
    • 2022-07-22
    • 2020-07-09
    • 2018-12-13
    • 2020-05-01
    • 1970-01-01
    相关资源
    最近更新 更多