Search code examples
amazon-dynamodbrelayjsrelay

Does relay require an id field in the the database?


Well, I have been using Relay for a while now, and I am realising that I am still not sure about some fundamental aspects of using Relay, Graphql, React and Dynamodb.

Im using Dynamodb as the database and Dynamodb discourages the use of uuids as identifiers. At the same time, the relay Nodedefinitions function expects to output an object with a type and an id field, so my question is, can you reconcile the best practice for Relay and for Dynamodb?

Or is it just me who does not understand?


Solution

  • Relay doesn't have any requirements of your database. You can use whatever kind of primary key in Dynamo that you want.

    You'll end up with two functions:

    1. f(relayId) -> dynamoEntity
    2. g(dynamoEntity) -> relayId

    Those functions can be implemented however you like. E.g. maybe you can base64-encode the Dynamo primary key to produce a relay id.