Generate IDs on the client

I’m using Slash GraphQL and am considering generating IDs on the client.

Is it possible to generate IDs on the client for GraphQL / Dgraph and if so could you just point me in the direction to be able to generate a unique ID and send it to Slash GraphQL?

Thank you!

You can used the @id directive to assign strings as ID. So process would be on the client side use something like uuid to generate unique keys and then use them in mutations when adding new data.

This means 2x unique fields: ID and UUID. Can we just generate a unique 64 bit identifier the same way Dgraph does for the ID so there is only 1 unique identifier?

Not to my knowledge. From my understanding zero server is responsible for generating these IDs and has a process to reserve a bulk set and then release the ones not used.

Right ok - thank you @amaster507 very helpful, so I would create a second unique id which I would use as the source of truth for the client and disregard Dgraph self-generated ID all-together apart from dealing with associations I guess.

If you use the @id then you can use your custom id for linking relationships too. The dgraph uid would not be available then on the graphql endpoint, but it does still exist in the underlying DQL

Amazing, I didn’t think of that either. A big thank you @amaster507 :pray:

1 Like