RFC: Allow multiple unique fields in graphql schema

RFC: Allow multiple fields with @id directive in a graphql type.

Summary

Currently, we support external ID fields in graphql using @id directive. A type can have only one field with @id directive and that field is unique across nodes of that type. In addition to it we don’t allow a type with @id directive to be updated.

To gives users the flexibility to have multiple unique fields, We are now extending this support to include multiple @id fields in a type.

Changes

  1. Now users can have multiple fields with the @id directive. And no two nodes can have the same value for the any of fields with the @id directive.

  2. Users won’t be able to update the fields with @id directive.We will add it later.

  3. 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.
    For example, below graphql query

query {
      getBook(id: "0x1",title:"GraphQL",ISBN:"001HB") {
        id
        title
        ISBN
        Author
      }
    }

will be written to below dgraph query

    query {
      getBook(func: uid(0x1)) @filter(((eq(Book.title, "GraphQL") AND eq(Book.ISBN, "001HB")) AND type(Book))) {
        id : uid
        title : Book.title
        ISBN : Book.ISBN
        Author : Book.Author
      }
    }
  1. If in a type, there are multiple @id fields, then in arguments to get Query these fields will be optional, and if in a type there is only one field defined with either @id or ID, then that will be a required field in arguments of get Query.
1 Like

I think the fields should allow for updates. I had to update a field here recently and had to revert to DQL to do it.

1 Like

I would agree. Needing a unique field and needing an immutable field are different needs that I hope will not be conflated.

2 Likes

yeah, for now, we will allow multiple @id fields in a type. Since @id fields are not updateable, so this will apply to all @id fields.

But we will have a different RFC soon for the feature where we will make @id fields mutable once we allow multiple @id fields.

How is this RFC going?

You can follow the development on this PR:
https://github.com/dgraph-io/dgraph/pull/7235

2 Likes

Support for multiple @id fields is merged in master now.

4 Likes

@JatinDevDG is this available on Slash now ?

Hi @elyn_T.G , this feature will be released in 21.03 , then slash will be upgraded to 21.03.
It will take around 2 weeks of time.

2 posts were split to a new topic: Editable @id fields

2 posts were split to a new topic: Nullable @id field

2 posts were split to a new topic: Composite @id fields