Can't use array index in computed fields

I have a schema like this with Attribute and Group collections. Each attribute can reference multiple groups:

collection Attribute {
    name: String
    value: String

    groups: Array<Ref<Group>>

    index byGroup {
        terms [mva(.groups)]
    }
}

collection Group {
    name: String
}

I’m trying to follow the docs and query all attributes which have a particular group in the array. This query works:

let group = Group.byId("402314708599701568")

group {
  name,
  attributes: Attribute.byGroup(group) {
    name,
    value
  }
}

Now I wanted to convert this into a computed field. I did this:

compute attributes = ((group) => Attribute.byGroup(group))

But I get an error when I try to save the schema:

Type `{ name: String, attributes: Never, id: ID, ttl: Time | Null }` is not a subtype of `Array<Ref<Group>>`

Can anyone tell me what am I doing wrong?

Hi @heraldofsolace and welcome :wave: !

It looks like you are doing everything correctly. We can reproduce the issue where the types for calling an index with an MVA term are incorrectly interpreted. The issue is only when defining schema, not type-checking queries, which, as you reported, works fine.

Thanks for reporting! We have an internal ticket to prioritize and fix this.

1 Like

Hello,
I agree with this.

@heraldofsolace @ridabaig The fix for this should be deployed now. Please let us know if you still have issues!

Thank you!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.