graphile / crystal-pre-merge

Repository moved
https://github.com/graphile/crystal
39 stars 10 forks source link

Documentation: turning Node ID into underlying database ID #458

Open benjie opened 11 months ago

benjie commented 11 months ago

See https://discord.com/channels/489127045289476126/498852330754801666/1138749365096304660

Yeah, I guess I need to add something like https://postgraphile.org/postgraphile/next/make-extend-schema-plugin#mutation-example-with-node-id to https://postgraphile.org/postgraphile/next/node-id to help people find it.

This also depends on graphile/crystal#2013 really.

benjie commented 11 months ago

Specifically, it's

const handler = build.getNodeIdHandler("Chain");

and

const spec = specFromNodeId(handler, $nodeId);
const $id = spec.id;

Or something like that, depending on the shape of your table. E.g. if you have a composite primary key (organization_id, issue_id) then it might be:

const {
  organization_id: $organizationId,
  issue_id: $issueId,
} = specFromNodeId(handler, $nodeId);

Also note that if the NodeID is incompatible with this type then these values will be null (I think?)