1

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

pfried
  • 5,000
  • 2
  • 38
  • 71

1 Answers1

1

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.

Milan Gatyás
  • 2,509
  • 1
  • 17
  • 23
  • even tough that does not relate to aws-cdk directly it might be the right answer anyway (the approach taken in the link). But in that case it would be helpful if the typescript API does reject the type there – pfried Feb 05 '21 at 06:32