{"id":13720375,"url":"https://github.com/autoguru-au/graphql-dotnet-relay","last_synced_at":"2025-05-07T12:31:19.864Z","repository":{"id":79188267,"uuid":"252960557","full_name":"autoguru-au/graphql-dotnet-relay","owner":"autoguru-au","description":"Relay support for graphql-dotnet","archived":true,"fork":false,"pushed_at":"2021-04-01T08:51:04.000Z","size":41,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-01T12:41:51.383Z","etag":null,"topics":["graphql","graphql-dotnet","graphql-server","relay","relay-server"],"latest_commit_sha":null,"homepage":null,"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}},"created_at":"2020-04-04T09:51:20.000Z","updated_at":"2023-01-28T09:48:21.000Z","dependencies_parsed_at":"2023-03-25T20:02:27.192Z","dependency_job_id":null,"html_url":"https://github.com/autoguru-au/graphql-dotnet-relay","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fgraphql-dotnet-relay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fgraphql-dotnet-relay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fgraphql-dotnet-relay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoguru-au%2Fgraphql-dotnet-relay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autoguru-au","download_url":"https://codeload.github.com/autoguru-au/graphql-dotnet-relay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252876387,"owners_count":21818173,"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","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":["graphql","graphql-dotnet","graphql-server","relay","relay-server"],"created_at":"2024-08-03T01:01:03.081Z","updated_at":"2025-05-07T12:31:16.245Z","avatar_url":"https://github.com/autoguru-au.png","language":"C#","funding_links":[],"categories":["C#"],"sub_categories":[],"readme":"# graphql-dotnet-relay\n\u003e :warning: **Disclaimer** \n\u003e \n\u003e AutoGuru no longer use graphql-dotnet in our GraphQL stack. \n\u003e \n\u003e As such we're no longer actively maintaining it ourselves.\n\nThis library provides useful bits for graphql-dotnet based servers to add relay support. \n\n## Features\n\n### Node support\nRelay requires that:\n1. all queryable types in your graph implement a base type `Node`, and\n2. are queryable via query fields of form `node(id: ID!)` and `nodes(ids: [ID!]!)`.\n\nWe offer two classes to make this easy for you.\n\n#### `QueryGraphType`\nUse this as the base for your root `query` field you attach to your schema and \nIt'll add the `node` and `nodes` fields mentioned above.\n\n#### `NodeGraphType\u003cTSourceType, TId\u003e`\nUse this as the base for your own types, instead of `ObjectGraphType\u003cTSourceType\u003e` and \nit'll add two fields, `id` and `dbId` (where `id` is the Relay-spec compliant field required by all `Node` types,\nand `dbId` is your own internal id for that type, that you may need for displaying in your UI).\n\n### `ID` support\n\n#### Translations\nAlthough an `ID` is great for Relay, it's not great for humans or for use in our internal code. \nFurthermore, once you jump on the Relay train, you'll want to replace all your id-referencing field arguments with `ID!`\n\nThat causes a few issues:\n1. How can I query for data when dev'ing without first getting the global ID?\n   1. Similarly, I want my website's URLs to contain my friendlier id, like /blog/1, how can I call graph with that without first translating that into a global ID?\n2. How can I migrate to Relay support gradually without all my clients breaking by passing `1` or `\"1\"`?\n3. How can I deserialize a global `ID` in my resolver to a value I understand internally to resolve my data?\n\nTo make this easier, we:\n1. Hookup wiring to support parsing `string` or `TId` into a `ID`, so you can safely pass \"1\" or `1` in place of a real global `ID`.\n2. Provide extension methods you can use in your resolver to read global `ID`s into the real id you know and love.\n\nThere's also a `GlobalIdParser` if you ever need to work with global IDs yourself.\n\n#### Strongly-typed `ID` classes\nWe offer some built-in types for variations of global IDs (e.g. `GuidGlobalId`, `IntGlobalId`, `LongGlobalId`, `StringGlobalId`)\nso that you can read a complex field argument as a DTO class and use properties like `IntGlobalId`.\n\n#### AutoMapper converters\nIf you're using AutoMapper to translate between say an `InputDto` and another type,\nyou can have a DTO with a `IntGlobalId` property and map that to a type with an `int` property.\n\n#### NewtonsoftJson converters\nSimilar to above but for NewtonsoftJson. Call `JsonSerializerFactory.Create()` to get a serializer that can read/write \nthese ID-types into the equivalent BCL type to work with. Or use them like you would any other\nNewtonsoft.Json converter.\n\n### FluentValidation integration\nIf you're using FluentValidation, you can validate a strongly-typed global ID class's value like so:\n\n`RuleFor(x =\u003e x.Id).ValidGlobalId()`\n\n### JSResource field\nWIP\n\n## Usage\n\n\u003e Note: Versions 1.x are for GraphQL 2.4.0. \n\u003e Versions 2.x are for GraphQL 3.0.0-preview-x\n\nInstall from NuGet:\n\n`\u003e dotnet add package GraphQL.RelaySupport`  \n`\u003e dotnet add package GraphQL.RelaySupport.AutoMapped`  \n`\u003e dotnet add package GraphQL.RelaySupport.FluentValidation`  \n`\u003e dotnet add package GraphQL.RelaySupport.NewtonsoftJson`  \n`\u003e dotnet add package GraphQL.RelaySupport.Core`  \n\nIn your `Startup.cs`:\n1. Call `services.AddRelaySupport();`\n2. For AutoMapper support, include our profile when registering it, `services.AddAutoMapper(..., typeof(GlobalIdsProfile))`\n\nUpdate your root Query type to inherit from `QueryGraphType`.\n\nFor each of your relevant graph types:\n1. Inherit from `NodeGraphType\u003cTSourceType, TId\u003e`, specifying `TId` as the type you use internally, e.g. `int`.\n2. Call base constructor, passing an `idSelector` func, e.g. `myType =\u003e myType.Id`.\n3. Implement the abstract `GetByIdAsync` method, which will receive the real database id of your type.\n\nIn your field resolvers:\n* If you want an id/s argument, use `context.GetIntIdFromGlobalIdArgument(\"argName\")` or relevant overload.\n* If you want a complex argument, use standard `context.GetArgument\u003cT\u003e` from `GraphQL` project, but use the strongly-typed `ID` classes on your propeties where needed.\n\n## License\n\nMIT \u0026copy; [AutoGuru](https://www.autoguru.com.au/)\n\n\u003ca href=\"http://www.autoguru.com.au/\"\u003e\u003cimg src=\"https://cdn.autoguru.com.au/images/logos/autoguru.svg\" alt=\"AutoGuru\" width=\"150\" /\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautoguru-au%2Fgraphql-dotnet-relay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautoguru-au%2Fgraphql-dotnet-relay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautoguru-au%2Fgraphql-dotnet-relay/lists"}