{"id":30284776,"url":"https://github.com/autoguru-au/hotchocolate-polymorphic-ids","last_synced_at":"2025-09-07T07:10:35.613Z","repository":{"id":37207989,"uuid":"355193742","full_name":"autoguru-au/hotchocolate-polymorphic-ids","owner":"autoguru-au","description":"Adds polymorphic input ID support to HotChocolate","archived":false,"fork":false,"pushed_at":"2025-02-19T03:46:34.000Z","size":78,"stargazers_count":18,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-29T09:57:35.972Z","etag":null,"topics":["hotchocolate","ids","relay"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/autoguru-au.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-06T13:12:58.000Z","updated_at":"2025-02-19T02:13:24.000Z","dependencies_parsed_at":"2024-02-29T21:43:21.524Z","dependency_job_id":null,"html_url":"https://github.com/autoguru-au/hotchocolate-polymorphic-ids","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/autoguru-au/hotchocolate-polymorphic-ids","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fhotchocolate-polymorphic-ids","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fhotchocolate-polymorphic-ids/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fhotchocolate-polymorphic-ids/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fhotchocolate-polymorphic-ids/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autoguru-au","download_url":"https://codeload.github.com/autoguru-au/hotchocolate-polymorphic-ids/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fhotchocolate-polymorphic-ids/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274006246,"owners_count":25206104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hotchocolate","ids","relay"],"created_at":"2025-08-16T19:18:49.818Z","updated_at":"2025-09-07T07:10:35.605Z","avatar_url":"https://github.com/autoguru-au.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polymorphic IDs\n\n\u003cdiv\u003e\n  \u003cp\u003e\n\t  \u003ca href=\"https://www.nuget.org/packages/AutoGuru.HotChocolate.PolymorphicIds\"\u003e\u003cimg alt=\"Nuget version\" src=\"https://img.shields.io/nuget/v/AutoGuru.HotChocolate.PolymorphicIds\"\u003e\u003c/a\u003e\n\t  \u003ca href=\"https://www.nuget.org/packages/AutoGuru.HotChocolate.PolymorphicIds\"\u003e\u003cimg alt=\"NuGet downloads\" src=\"https://img.shields.io/nuget/dt/AutoGuru.HotChocolate.PolymorphicIds\"\u003e\u003c/a\u003e\t  \n      \u003ca href=\"https://codecov.io/gh/autoguru-au/hotchocolate-extensions/PolymorphicIds\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/autoguru-au/hotchocolate-polymorphic-ids/branch/main/graph/badge.svg?token=95TCHXVJTS\"/\u003e\n      \u003c/a\u003e    \n  \u003c/p\u003e\n\u003c/div\u003e\n\nThis package adds support to [ChilliCream](https://chillicream.com/)'s \n[HotChocolate](https://github.com/ChilliCream/hotchocolate) for \npolymorphic Relay / Global IDs so that you can pass the database id in as an `ID` in \nan input/argument and it'll be accepted.\n\nFor example, if you read the description of an `ID` type in GitHub's GraphQL API, it says:\n\u003e When expected as an input type, any string (such as \"4\") or integer (such as 4) input value will be accepted as an ID.\n\nThe following becomes possible (on args/input fields annotated with HotChocolate's `[ID]` attribute).\n```graphql\n# Schema\ntype Query {\n  booking(id: ID!): Booking\n}\n\n# Query\nquery {\n  bookingByGlobalId: booking(id: \"TheGlobalIdValue7sghdyg=\") { ... }\n  \n  bookingByDbId: booking(id: 1) { ... }\n  \n  bookingByDbIdString: booking(id: \"1\") { ... }\n}\n```\n\n## More details \n\n### Why would you do this?\n\n1. To achieve friendly URLs, like `/booking/123`, you need to be able to get a booking by its database id (`123`) as the client doesn't have the global ID. But it's nasty to have to expose a `bookingByDbId(id: Int!)` field to do so.\n1. For easier debugging. As humans we use database ids. So if you've got one, you can just pass it on through.\n\n### What's supported?\n\nCurrently only arguments / input fields that are annotated with the `[ID]` attribute will be noticed and have support added for handling different ids.\nSpecifically, the fluent-style declaration `.ID()` won't be handled right now; though support could \nbe added for it in the future so shout out if you need it on the [open issue](https://github.com/autoguru-au/hotchocolate-polymorphic-ids/issues/5).\n\nArrays of IDs are handled (but only v2+ can support arrays of nullable IDs (`[ID]` or `[ID]!`) due to a bug in Hot Chocolate v11).\n\nIDs that are internally represented with `int`, `Guid`, `long` or `string`, and their nullable equivalents will be handled. \nYou can opt-out of each's support as required.\n\nFor integer-based IDs, you can pass `\"1\"` or `1` and both will be accepted.\n\nFor all other types, you need to pass the string value, e.g. \n* `\"26a2dc8f-4dab-408c-88c6-523a0a89a2b5\"` for a guid-based ID\n* `\"123456789\"` for a long-based ID\n\n### Any downsides?\n\n1. Strings are a problem. It's difficult to distinguish between the global id format and a string database id. \nAs such, in this case, we try to read it as a global id and if that throws we consider it a database id. \nThe one problem being that invalid global ids, e.g. you missed one char, will be considered a database id. \nIf you don't have string db ids, it's a good idea to just turn off their handling so an invalid global id would still throw (see setup below).\n2. There's a performance hit to the interception, but it'd be barely measurable.\n3. Once you go down this path, it's very difficult to go back as your clients will start to rely on this.\n\n## Setup\n\nInstall a [compatible version](#Compatibility) of the \n[package from NuGet](https://www.nuget.org/packages/AutoGuru.HotChocolate.PolymorphicIds)\n\n```bash\ndotnet add package AutoGuru.HotChocolate.PolymorphicIds\n```\n\nConfigure it on your schema (`ISchemaBuilder`) or executor (`IRequestExecutorBuilder`):\n```c#\n.AddGlobalObjectIdentification() // Required since Hot Chocolate v12.6.0+\n.AddPolymorphicIds(new PolymorphicIdsOptions\n{\n    HandleGuidIds = false,    // true by default\n    HandleIntIds = true,      // true by default\n    HandleLongIds = false,    // true by default\n    HandleStringIds = false,  // true by default\n});\n```\n\n### Adding a dbId field declaratively\n\nAt AutoGuru we add a `dbId` field to all our nodes. Since this is essentially the same as declaring the node's `id` field, we've got\nsome helpers for this that can be found [here](https://gist.github.com/benmccallum/89d4d5b604d67094418956db43386ce5).\n\nCurrently this is a manual/explicit thing you need to do, but in future this will ideally become automatic via a type interceptor\nif I can figure out how to get that to work (last attempt failed :P).\n\n\n## Compatibility\n\nWe depend on [HotChocolate.Execution](https://www.nuget.org/packages/HotChocolate.Execution)\nwhich can bring breaking changes from time to time and require a major bump our end.\nCompatibility is listed below.\n\nWe strive to match Hot Chocolate's supported .NET target frameworks, though this might not always be possible.\n\n| HotChocolate | Polymorphic IDs | Our docs   |\n| ------------ | --------------- | -----------|\n|      v13.0.0 |              v4 | right here |\n|     v12.6.0* |              v3 | [/v3/main](https://github.com/autoguru-au/hotchocolate-polymorphic-ids/tree/v3/main) branch |\n|      v12.0.0 |              v2 | [/v2/main](https://github.com/autoguru-au/hotchocolate-polymorphic-ids/tree/v2/main) branch |\n|      v11.1.0 |              v1 | [/v1/main](https://github.com/autoguru-au/hotchocolate-polymorphic-ids/tree/v1/main) branch |\n\n\\* Denotes unexpected binary incompatibility / breaking change in Hot Chocolate\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautoguru-au%2Fhotchocolate-polymorphic-ids","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautoguru-au%2Fhotchocolate-polymorphic-ids","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautoguru-au%2Fhotchocolate-polymorphic-ids/lists"}