hydra icon indicating copy to clipboard operation
hydra copied to clipboard

Constructor parameters for variants

Open ondratra opened this issue 3 years ago • 0 comments

Variants can't be initialized via the constructor and their properties must be set after the object creation. Add the same possibility to initialize variants in the constructor the same way entities do.

Assuming input schema:

type MyEntity @entity {
  myData: Int!
}

type MyEntityWithVariant @entity {
  myVariantValue: MyVariant!
}

type MyVariant1 @variant {
  myData: Int!
}

type MyVariant2 @variant {
  myData: Int!
}

union MyVariant = MyVariant1 | MyVariant2

We can currently init entities like this:

const myEntity = new MyEntity({ myData: 1 })

but variants can't be initiated like that, and properties must be set afterward:

// const myVariant1 = new MyVariant1({ myData: 1 }) // this will fail: `Expected 0 arguments, but got 1`
const myVariant1 = new MyVariant1()
myVariant1.myData = 1

ondratra avatar Sep 29 '21 20:09 ondratra