Multiple Annotations of Same Type on Fields?

#1

I haven’t tested this on types yet, but I am experiencing the following issue with fields:

type A {
@foo(1)
@foo(2)
@foo(3)
myField: string
}

When I get the field object out of A.fields() and ask myField.extensions() I only get back Foo: { val: 3 } and Foo 1 and Foo 2 are lost.

Is there a mechanism in place to allow multiple annotations of the same type on a field?

0 Likes

#2

It would likely be more accurate to define your annotation Foo as:

type Foo {
values: [int]
}

and then to use it as:
@foo(values = [1, 2, 3])
type A

is there a particular reason you have defined your annotation in the above way?

0 Likes

#3

Okay,
That makes sense, can it support custom types as well? So I could say:

type Foo {
values: [myNewType]
}

and then to use it as:
@foo(values = [{val:1},{val:2},{val:3}])
type A

0 Likes

#4

Yes

e.g.

@annotation(appliesTo=[‘field’])
type Ann.CalculatedMetric {

metric: ResourceMetric
estimate: MetricEstimate
measurement: MetricMeasurement
}

1 Like

#5

Excellent! Thank you!

0 Likes