Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

To avoid duplication of data structures I wanted to reuse a type definition on an input type like this

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()
    }
});

There is no error since the return type of DeviceStatus.attribute() is fine, and this works for ObjectType inheritance.

From my perspective this should work, but deploying results in a nasty "Internal Error creating Schema" error.

Of course I could move the whole definition into an object and reuse it but that seems weird. Is there any good solution on this for the CodeFirst approach

question from:https://stackoverflow.com/questions/66046744/aws-cdk-appsync-codefirst-input-types

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
679 views
Welcome To Ask or Share your Answers For Others

1 Answer

It seem to be invalid to reference object type in input type.

I recommend to view Can you make a graphql type both an input and output type?

Probably best you can do is to create some convenience method which will create you both object and input type from single definition.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...