How To Use Nullable @id Fields?

Report a GraphQL Bug

What edition and version of Dgraph are you using?


  • SlashGraphQL
  • Dgraph (community edition/Dgraph Cloud)

If you are using the community edition or enterprise edition of Dgraph, please list the version:

Dgraph Version
$ dgraph version
Latest dgraph/dgraph Image (v23.0.1) running via Docker Container. 

Have you tried reproducing the issue with the latest release?

Tried on latest version and on dgraph/standalone Docker image @v20.0.3 (I think that’s the version standalone runs on).

Steps to reproduce the issue (paste the query/schema if possible)

type User {
  id: ID
  email: String! @id @search(by: [hash])
  username: String @id @search(by: [hash])

Expected behaviour and actual result.

curl -X POST localhost:8080/admin/schema --data-binary '@./dgraph/schema.graphql'
When running the above curl command to initialize my schema in the db, it should simply return a success message but it returns the below message:

{"errors":[{"message":"resolving updateGQLSchema failed because input:47: Type User; Field username: with @id 
directive must be of type String!, Int! or Int64!, not String\n (Locations: [{Line: 3, Column: 4}])","extensions":{"code":"Error"}}]}

If I make the username a non-nullable field, it works, but I thought having a nullable @id field was possible in dgraph version >= 21.07 after reading these posts: Nullable @id field & RFC: Mutable and null able @id field in GraphQL. Am I misunderstanding something here? It seems that I can’t get it to work in my dev environment. Is there something I’m missing in my implementation?

Any help would be greatly appreciated :slight_smile:

PS - Sorry if this is the wrong topic to place this, wasn’t sure.

Hey Zane,

Unfortunately this nullable @id concept was introduced in a branch that was abandoned by the new Dgraph team. V22 (and the current version) was cut from the v21.03 release.

@Raphael, is this RFC being considered for a future release?

Hey Matthew,

Thanks for the response! I was able to get @id directive to work with the dgraph/standalone:v21.12.0 Docker image, along with @default directives but obviously that version is no longer being supported. It would be great if these were implemented in the newer versions of Dgraph but I understand that it’s not a necessity, more of a QoL thing.

Thank you for clearing up my confusion! I was assuming that it would be supported in current versions since it was used in previous versions but that was my mistake.