Composite @id fields

Hi,

will this RFC also include composite indexes?
E.g. in this example I want to allow unique names within a group of bars, i.e. the uniqueness should only be validated for the composite pair (fooID, name).

type Foo {
  id: String! @id
  bars: [Bar!]!
}

type Bar @id(fooId, name) {
  fooId: String!
  name: String!
}
1 Like

No, composite indexes are not part of this.

We will add this as a feature request to our internal backlog, seems like a use-case that we should support.

Thanks

2 Likes

This would be really useful for us as well. I thought this was part of RFC: Allow multiple unique fields in graphql schema due to (emphasis mine):

We can filter the results using multiple id fields. getQuery will now accept many fields which have @id field. All of them will be connected using And filter in resulting query.

To clarify, the existing support for multiple @id fields requires each field to be unique by itself and the “AND filtering” would mostly be a no-op (unless you passed two conflicting IDs that don’t actually exist as a pair)?

True

I think you need to correct this to:

and the “AND filtering” would mostly be a no-op (unless you passed two IDs that actually exist as a pair)

1 Like

Hopefully you guys add this feature. In the mean time, you can emulate this functionality like so:

type Foo {
  id: String! @id
  bars: [Bar!]!
}

type Bar {
  name_fooId: String! @id
  fooId: String!
  name: String!
}

Of course, another use case for @prehooks to validate this or do this automatically :slight_smile:

J