Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Independent usage options for nodeIds and row ids #714

Closed
1 of 3 tasks
micimize opened this issue Mar 15, 2018 · 9 comments
Closed
1 of 3 tasks

Independent usage options for nodeIds and row ids #714

micimize opened this issue Mar 15, 2018 · 9 comments

Comments

@micimize
Copy link

micimize commented Mar 15, 2018

I'm submitting a ...

  • bug report
  • feature request
  • question

PostGraphile version: ^4.0.0-beta.2

There are two aspects to this. postgraphile automatically generates

  • Query { item(nodeId: ID!): Item }
    but not Query { item(id: Int!): Item }
  • Parent { parentId: Int! childsByParentId }
    but not Parent { parentNodeId: ID! childsByParentNodeId }

This seems counter intuitive to me, as I would rather deal with one "identification abstraction" than two.

@benjie
Copy link
Member

benjie commented Mar 15, 2018

It's possible to drop the Node plugin and lose all the node interfaces if you like, but I'll break down your points in case it helps:

Query { item(nodeId: ID!): Item }
but not Query { item(id: Int!): Item }

There is itemById(id: Int!) though; and itemByUniqueKey1AndUniqueKey2(uniqueKey1: ..., uniqueKey2: ...) if the table has more unique constraints than just the primary key. A user may want to look up the element by any of its unique keys. Personally I almost never user the item(nodeId: ID!) interface; but others who prefer to use it might.

Parent { parentId: Int! childsByParentId }
but not Parent { parentNodeId: ID! childsByParentNodeId }

parentId is a literal property of the table in the database - it is a value in a column (the column parent_id or parentId depending on your naming conventions).

parentNodeId would be a computed field - we can totally add this, but I don't think it brings much value.

childsByParentId says "find all the 'childs' that have an id equal to this table's `parentId' (or 'parent_id') column"

childsByParentNodeId is unnecessary - the results you'd expect it to return would be exactly the same as the childsByParentId (since you're not passing it a value - it's inferring it from the table / relations) - adding it would seem highly redundant.

Ultimately the reasoning for these things comes from Relay 1, and if you don't want them in the schema I'd be happy to merge a PR that adds a flag to simplify the schema to remove certain of them. As I mentioned before, I think it might be as simple as disabling NodePlugin. Seems the method to remove plugins is not documented yet, so I'll add that as a task

@micimize
Copy link
Author

@benjie that makes perfect sense, I don't know why I missed the itemById(id: Int!). Must have been experiencing some cognitive dissonance.

If it is as simple as disabling the NodePlugin, probably a decent cli option would be --omit-plugins, but it doesn't bother me that much.

Maybe at some point I'll write a plugin for schema sugar like --default-query-field id or --shorten-child-connection-names. Anyways, thanks for the breakdown!

@eladkolet
Copy link

eladkolet commented Sep 9, 2018

Following up here, how can I remove both the default generation of itemById(id: Int!), itemByUniqueKey1AndUniqueKey2(uniqueKey1: ..., and disable the NodePlugin ?

Thanks!

@janusch
Copy link

janusch commented Oct 2, 2018

there is a --skip-plugins option in the docs. However running postgraphile with that option errors out.
How do you disable the generation of NodeId?

Thank you in advance!

@benjie
Copy link
Member

benjie commented Oct 2, 2018

I spotted this a couple of days ago myself as it happens; please subscribe to this issue and it will be closed when the issue is resolved: graphile/graphile-engine#310

I'm going to add tests for specifically supporting this case.

@janusch
Copy link

janusch commented Oct 2, 2018

Fantastic, thanks for the quick reply and the great work on postgraphile!!!

@204NoContent
Copy link

@benjie Related to this question, is there a setting to automatically generate a Relay (modern) compliant schema if the database already uses UUIDs for primary keys? Basically the classicIds setting, but using the existing id column since it is already globally unique? Any guidance would be greatly appreciated 😄

@benjie
Copy link
Member

benjie commented Oct 8, 2018

No, because the UUID does not encode in it which collection it is from, so given a UUID we do not know which table to retrieve the record from (and scanning through hundreds of tables to find it would be highly inefficient). You can replace the nodeId plugins with your own should you so choose, enabling you to solve this issue for your stack.

@204NoContent
Copy link

@benjie Ok cool. Thanks for explaining the design choice and thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants