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
-
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. -
Users won’t be able to update the fields with
@id
directive.We will add it later. -
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 usingAnd
filter in resulting query.
For example, belowgraphql
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
}
}
- 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
orID
, then that will be a required field in arguments of get Query.