graphile / crystal-pre-merge

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

Improve error message for `resource.get` that isn't unique #474

Open benjie opened 11 months ago

benjie commented 11 months ago
   "message": "An error occurred (logged with hash: 'Attempted to call PgResource(dependency).get({id}) at child field (TODO: which one?) but that combination of attributes is not unique (uniques: [{\"isPrimary\":true,\"attributes\":[\"block_id\",\"dependency_id\"],\"extensions\":{\"tags\":{}}}]). Did you mean to call .find() instead?\n\nGraphQL HTTP Request:5:5\n4 |     success\n5 |     dependency {\n  |     ^\n6 |       id')",

Reported by @sgrove

Context: https://discord.com/channels/489127045289476126/498852330754801666/1139357431210704947

This error would be more helpful if it found the primary unique and then told you to do that instead, e.g.:

Attempted to call PgResource(dependency).get({id: ...}) at child field (TODO: which one?) but {PROBLEM}. Valid calls would look like {one of}: `.get({ block_id: ... })`, `.get({ organization_id: ..., number: ... })`, or if you want more than one record use `.find()` instead.

Where {PROBLEM} is something like:

- `id` is not a column of `{RESOURCE_NAME}`
- {these keys|this key} (`id`) does not uniquely identify a record