0

I'm new to GraphQL and I'm using Relay as my client and PostGraphile as my schema generator. My database is based on this PostgreSQL Schema Design.

My tables are person, post and image and the primary key is a column called id with type uuid.

When PostGraphile generates my schema, it renames the id column to rowId and keeps the id column but with a different type of random key, presumably a record id unique across all tables.

Should I rename all my primary uuid columns person_id, post_id, image_id and so forth? Or is there a way to change how exportGqlSchemaPath handles id's?

Kirk Ross
  • 6,413
  • 13
  • 61
  • 104
  • 1
    You could call them all `pk` instead of `id`. Or don’t use --classic-ids. Or accept the naming since relay prefers `id: ID` (I think). Up to you really – Benjie Jan 21 '21 at 07:47
  • Thanks @Benjie -- I don't mind either way. I'm curious why PostGraphile (if PostGraphile is in fact doing it) adds an additional id column which isn't in the db. But come to think of it, I think you actually explained it (or maybe Chad Furman) in the docs somewhere that it's an "invisible" id unique across all tables. Invisible in that it's not in actually in the database. – Kirk Ross Jan 22 '21 at 08:32
  • It's to conform to https://relay.dev/graphql/objectidentification.htm, we need to give every `Node` an `id: ID!` and from an `id: ID!` we need to be able to get back to the `Node` (so we have to know which data store it comes from; UUID is not sufficient for this). – Benjie Jan 22 '21 at 17:42
  • @Benjie Lightbulb! And I just now found the explanation on the /postgrahile/node-id page. Thank you. Followup philosophy question: In a Relay / GraphQL environment, is there even a need for a pk/uuid field if every node is going to get an id: ID!? – Kirk Ross Jan 22 '21 at 20:10
  • Potentially not, but due to technical limitations you may need it with PostGraphile (e.g. for passing PK to custom mutation functions). – Benjie Jan 23 '21 at 22:29

0 Answers0