pg_graphql icon indicating copy to clipboard operation
pg_graphql copied to clipboard

Add support for single record queries by primary key

Open spitfire55 opened this issue 8 months ago • 7 comments

What kind of change does this PR introduce?

Users can now use [table_name]ByPk(key) queries to get a single record using the primary key

What is the current behavior?

No first-party support for single record queries by primary key.

See #554 .

What is the new behavior?

Adds a [table_name]ByPk(pk: pk_type) method to all tables that define a primary key

spitfire55 avatar May 04 '25 18:05 spitfire55

Hey @spitfire55 , thanks for this PR. We haven't forgotten this, just totally slammed right now. Will come back to it eventually.

@olirice before we review this, do you an opinion on the approach here. Do we want to add a method to access object by pk as implemented in this PR?

imor avatar May 08 '25 12:05 imor

yes, i think there's been enough demand for it to justify the addition + it doesn't introduce any performance issues

Like Raminder mentioned, we're pretty slammed right now so it may take some time to work through this and review so sorry in advance for that!

From a very quick glance the things that jumped out are

  • lets filter the entities that automatically get these entrypoints to those that have primary keys of a type that's in a whitelist -> int, bigint, uuid, string are the ones that make sense to me
  • use exhaustive pattern matching where possible so its easier to find what needs updating when we extend enums in the future

appreciate your work on this, looking forward to getting it merged

olirice avatar May 08 '25 21:05 olirice

@imor @olirice any chance this can get reviewed and merged this week?

spitfire55 avatar Jul 22 '25 01:07 spitfire55

@spitfire55 I'll find some time today or tomorrow to review it. Sorry for the delay and thanks again for your patience.

imor avatar Jul 22 '25 05:07 imor

LGTM apart from missing docs. @olirice would you like to take a look?

imor avatar Jul 22 '25 07:07 imor

@spitfire55 would you mind making changes suggested by @olirice.

imor avatar Jul 23 '25 05:07 imor

Yep, I'll tackle these this week.

spitfire55 avatar Jul 30 '25 01:07 spitfire55