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

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

code first - AWS-CDK Appsync Codefirst input types

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...