{"id":13731287,"url":"https://github.com/sahb1239/SAHB.GraphQLClient","last_synced_at":"2025-05-08T04:32:27.592Z","repository":{"id":52989974,"uuid":"103029642","full_name":"sahb1239/SAHB.GraphQLClient","owner":"sahb1239","description":"Query HTTP api using GraphQL. The client recieves a model as typeparameter and then queries the GraphQL api and deserilize the result.","archived":false,"fork":false,"pushed_at":"2022-07-07T23:26:41.000Z","size":671,"stargazers_count":44,"open_issues_count":20,"forks_count":14,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-04-25T18:59:00.468Z","etag":null,"topics":["csharp","graphql","graphql-client","object-mapper"],"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/sahb1239.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}},"created_at":"2017-09-10T13:00:18.000Z","updated_at":"2024-08-30T06:27:03.000Z","dependencies_parsed_at":"2022-08-28T12:13:53.399Z","dependency_job_id":null,"html_url":"https://github.com/sahb1239/SAHB.GraphQLClient","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sahb1239%2FSAHB.GraphQLClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sahb1239%2FSAHB.GraphQLClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sahb1239%2FSAHB.GraphQLClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sahb1239%2FSAHB.GraphQLClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sahb1239","download_url":"https://codeload.github.com/sahb1239/SAHB.GraphQLClient/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252883362,"owners_count":21819167,"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":["csharp","graphql","graphql-client","object-mapper"],"created_at":"2024-08-03T02:01:26.481Z","updated_at":"2025-05-08T04:32:27.175Z","avatar_url":"https://github.com/sahb1239.png","language":"C#","funding_links":[],"categories":["C#"],"sub_categories":[],"readme":"# SAHB.GraphQL.Client\nQuery HTTP api using GraphQL. The client recieves a model as typeparameter and then queries the GraphQL api and deserilize the result.\n\n## Nuget\nThe library can be found on NuGet with the package name [SAHB.GraphQL.Client](https://www.nuget.org/packages/SAHB.GraphQL.Client/).\nFor pre release builds the NuGet package feed from [AppVeyor](https://ci.appveyor.com/nuget/sahb-graphqlclient-jry5sxi8qeq7) can be used.\n\nOlder versions (1.1 and later) can be found on [SAHB.GraphQLClient](https://www.nuget.org/packages/SAHB.GraphQLClient/).\n\nIt can be installed using the following command in the Package Manager Console.\n\n```\nInstall-Package SAHB.GraphQL.Client\n```\n\n### The client supports the following frameworks:\n\n[SAHB.GraphQL.Client](https://www.nuget.org/packages/SAHB.GraphQL.Client/):\n- .NET Standard 1.2\n- .NET Framework 4.5.2\n\n[SAHB.GraphQL.Client.Subscription](https://www.nuget.org/packages/SAHB.GraphQL.Client.Subscription/):\n- .NET Standard 2.0\n- .NET Framework 4.5.2\n\n## Documentation\nDocumentation can be found in this readme and in [Documentation.md](Documentation.md) file.\n\n## Building\nIn order to build this project some additional steps is needed to generate a Version.props file. The easiest way is to execute the following commands:\n```\ngit submodule update --init --recursive\ncd Build\n.\\build.ps1 -Target \"Build\"\n```\n\nAnother way is creating the file Version.props. The file should be at the root directory of the repository and contain the following:\n```\n\u003cProject\u003e\n\t\u003cPropertyGroup\u003e\n\t\t\u003cVersion\u003e2.1.0-unstablebuild\u003c/Version\u003e\n\t\u003c/PropertyGroup\u003e\n\u003c/Project\u003e\n```\n\n## Examples\nAn example for the Starwars API.\n\n```csharp\n// TODO: Use dependency injection (services.AddGraphQLHttpClient()) (IServiceCollection)\n// Initilize GraphQLClient\nIGraphQLHttpClient client = GraphQLHttpClient.Default();\n\n// Get response from url\nvar response = await client.Query\u003cQuery\u003e(\"https://mpjk0plp9.lp.gql.zone/graphql\");\n\n// Get name etc.\nConsole.WriteLine(response.Hero.Name);\n```\n\nThe example uses the following query classes:\n```csharp\npublic class Query\n{\n   public CharacterOrPerson Hero { get; set; }\n}\n        \npublic class CharacterOrPerson\n{\n   public string Name { get; set; }\n   public IEnumerable\u003cFriend\u003e Friends { get; set; }\n}\n\npublic class Friend\n{\n   public string Name { get; set; }\n}\n```\n\nThe following code requests the endpoint with the following query\n```\n{\"query\":\"query{hero{name friends{name}}}\"} \n```\n\nThe following using statements is required\n```csharp\nusing SAHB.GraphQLClient;\nusing SAHB.GraphQLClient.Extentions;\n```\n\nMore examples can be found in [Examples.md](Examples.md)\n\n### Arguments\nIt's possible to add arguments to queries. This can be done with the attribute ```GraphQLArgumentAttribute```. This attribute takes 3 arguments where the first is argument name used on the GraphQL server. The second is the argument type, for example String. The third argument is the varible name which should be used when the query is requested.\n\n```csharp\npublic class Query\n{\n   [GraphQLArgumentAttribute(\"argumentName\", \"ArgumentType\", \"variableName\")]\n   public Hero Hero { get; set; }\n}\n```\n\nThe client is requested as shown here:\n```csharp\nvar response = await client.Query\u003cQuery\u003e(\"https://mpjk0plp9.lp.gql.zone/graphql\", \n   arguments: new GraphQLQueryArgument(\"variableName\", \"valueToBeSent\"});\n```\n\nThis will generate the query (Hero contains here only the Name property):\n```\n{\"query\":\"query{hero(argumentName:\\\"valueToBeSent\\\"){name}}\"}\n```\n\n### Renaming of a field\nTo rename a field name use the attribute ```GraphQLFieldNameAttribute``` on the class or property which you want to remap. For example request the field Fullname on the property Name do the follwing.\n```csharp\npublic class Friend\n{\n   [GraphQLFieldName(\"fullname\")\n   public string Name { get; set; }\n}\n```\n\nThis will generate the query:\n```\n{\"query\":\"query{hero{Name:fullname\"}\n```\n\nNote: For generating this you need to remember to add a extra Query class\n```csharp\npublic class Query\n{\n   public Hero Hero { get; set; }\n}\n```\n\n### Ignoring a field\nTo ignore a field use the attribute ```GraphQLFieldIgnoreAttribute``` on the class or property which you want to ignore. For example:\n```csharp\npublic class Hero\n{\n   public string Name { get; set; }\n\n   [GraphQLFieldIgnore]\n   public string IgnoredField { get; set; }\n}\n```\n\nExample for ignoring a class\n```csharp\npublic class Hero\n{\n   public string Name { get; set; }\n\n   public IgnoredClass IgnoredField { get; set; }\n}\n\n[GraphQLFieldIgnore]\npublic class IgnoredClass\n{\n   public string SomeProperty { get; set; }\n}\n```\n\nThis will generate the query:\n```\n{\"query\":\"query{hero{name}}\"}\n```\n\nNote: For generating this you need to remember to add a extra Query class\n```csharp\npublic class Query\n{\n   public Hero Hero { get; set; }\n}\n```\n\n## Subscriptions\nThe GraphQLclient has a subscription client which can be found here: [SAHB.GraphQLClient.Subscription](https://www.nuget.org/packages/SAHB.GraphQL.Client.Subscription/).\nDocumentation can be found in [Documentation.md](Documentation.md) file.\n\n## Introspection\nThe GraphQLclient has a package which contains a introspection query to inspect the GraphQL type system and a validator to validate C# queries against the introspection output. It can be found here: [SAHB.GraphQLClient.Introspection](https://www.nuget.org/packages/SAHB.GraphQL.Client.Introspection/).\nDocumentation can be found in [Documentation.md](Documentation.md) file.\n\n## Example projects\nExample projects can be found in the path examples\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahb1239%2FSAHB.GraphQLClient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsahb1239%2FSAHB.GraphQLClient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahb1239%2FSAHB.GraphQLClient/lists"}