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!
}
6 Likes

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

3 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)?

1 Like

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

1 Like

+1 would love to have this feature as a part of Dgraph!

+1 I have a use-case for this feature.

two extra use cases for this feature:

ticket:created means there is a github issue we can follow?

Any updates on this? Would really love the functionality!

I’ve created an issue in github, that would fix two issues at once, uniqueness and composite ids. Feel free to comment it:
https://github.com/dgraph-io/dgraph/issues/8117

Dgraph is currently restructuring their team so be patient, even the top priority issues will take probably some months to get fixed