{"id":19100000,"url":"https://github.com/Giorgi/GraphQLinq","last_synced_at":"2025-04-18T17:32:25.469Z","repository":{"id":37921841,"uuid":"82726693","full_name":"Giorgi/GraphQLinq","owner":"Giorgi","description":"LINQ to GraphQL - Strongly typed GraphQL queries with LINQ query syntax. No more magic strings and runtime errors.","archived":true,"fork":false,"pushed_at":"2023-07-18T11:20:21.000Z","size":305,"stargazers_count":204,"open_issues_count":22,"forks_count":22,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-05-01T21:19:24.246Z","etag":null,"topics":["csharp","graphql","json","linq","netcore"],"latest_commit_sha":null,"homepage":"https://www.giorgi.dev/dotnet/introducing-graphqlinq-strongly-typed-graphql-queries-with-linq-to-graphql/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Giorgi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"Giorgi","patreon":null,"open_collective":null,"ko_fi":"Giorgi","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://www.buymeacoffee.com/giorgidev"]}},"created_at":"2017-02-21T21:01:34.000Z","updated_at":"2024-04-18T15:28:49.000Z","dependencies_parsed_at":"2024-02-03T18:02:37.614Z","dependency_job_id":"710fdcf2-d6a7-4693-9a94-c392011ad73d","html_url":"https://github.com/Giorgi/GraphQLinq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Giorgi%2FGraphQLinq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Giorgi%2FGraphQLinq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Giorgi%2FGraphQLinq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Giorgi%2FGraphQLinq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Giorgi","download_url":"https://codeload.github.com/Giorgi/GraphQLinq/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783098,"owners_count":17201903,"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","json","linq","netcore"],"created_at":"2024-11-09T03:52:25.522Z","updated_at":"2024-11-09T03:52:52.739Z","avatar_url":"https://github.com/Giorgi.png","language":"C#","funding_links":["https://github.com/sponsors/Giorgi","https://ko-fi.com/Giorgi","https://www.buymeacoffee.com/giorgidev","https://ko-fi.com/U6U81LHU8"],"categories":["csharp","json"],"sub_categories":[],"readme":"# GraphQLinq\n\nLINQ to GraphQL - Strongly typed GraphQL queries with LINQ query syntax.\n\n\u003e You **must regenerate** your client code with GraphQLinq.Scaffolding after updating GraphQLinq.Client to a newer version\n\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=for-the-badge\u0026logo=Apache)](License.md)\n[![AppVeyor](https://img.shields.io/appveyor/build/Giorgi/graphqlinq/master.svg?style=for-the-badge\u0026logo=appveyor)](https://ci.appveyor.com/project/Giorgi/graphqlinq)\n[![Coverage Status](https://img.shields.io/coveralls/github/Giorgi/GraphQLinq?logo=coveralls\u0026style=for-the-badge)](https://coveralls.io/github/Giorgi/GraphQLinq)\n[![Ko-Fi](https://img.shields.io/static/v1?style=for-the-badge\u0026message=Support%20the%20Project\u0026color=success\u0026logo=ko-fi\u0026label=$$)](https://ko-fi.com/U6U81LHU8)\n\n\n[![](https://img.shields.io/nuget/dt/GraphQLinq.Client.svg?label=GraphQLinq.Client\u0026style=for-the-badge\u0026logo=NuGet)](https://www.nuget.org/packages/GraphQLinq.Client/)\n[![](https://img.shields.io/nuget/dt/GraphQLinq.Scaffolding.svg?label=GraphQLinq.Scaffolding\u0026style=for-the-badge\u0026logo=NuGet)](https://www.nuget.org/packages/GraphQLinq.Scaffolding/)\n\n![Project Icon](docs/Images/Icon.png \"GraphQLinq Project Icon\")\n\n## This library is not maintained any more. For a similar LINQ style GraphQL syntax library check out [ZeroQL](https://github.com/byme8/ZeroQL/)\n\n- [About The Project](#about-the-project)\n- [Getting Started](#getting-started)\n  - [Installing Scaffolding Tool](#installing-scaffolding-tool)\n  - [Scaffolding Client Code](#scaffolding-client-code)\n  - [Install GraphQLinq NuGet Package](#install-graphqlinq-nuget-package)\n- [Running GraphQL Queries with LINQ](#running-graphql-queries-with-linq)\n  - [Query all Primitive Properties of a Type](#query-all-primitive-properties-of-a-type)\n  - [Query Specific Properties](#query-specific-properties)\n  - [Include Navigation Properties](#include-navigation-properties)\n  - [Pass Parameters to Queries and Compose Queries](#pass-parameters-to-queries-and-compose-queries)\n  - [Include Multiple Levels of Navigation Properties](#include-multiple-levels-of-navigation-properties)\n  - [View Generated Query](#view-generated-query)\n- [Roadmap](#roadmap)\n- [Contributing](#contributing)\n- [License](#license)\n\n## About The Project\n\nGraphQLinq is a .NET tool for generating C# classes from a GraphQL endpoint and a .Net Standard library for writing strongly typed GraphQL queries with LINQ.\n\nWith GraphQLinq you will:\n\n- Write strongly typed queries with LINQ.\n- Have your queries checked by the compiler.\n- Run queries and deserialize JSON response into strongly typed classes in a single method call.\n- View queries generated by LINQ to GraphQL.\n\n## Getting Started\n\n### Install Scaffolding Tool\n\nBefore you starting writing queries, you need to generate classes from GraphQL types. This is done by `GraphQLinq.Scaffolding`, a .NET tool that is part of this project.\n\nTo get the tool, open your favourite command shell and run\n\n```sh\ndotnet tool install --global --version 1.1.0-beta GraphQLinq.Scaffolding\n```\n\nRunning this command will install the `GraphQLinq.Scaffolding` tool and make it available globally for all projects.\n\n### Scaffolding Client Code\n\nNext, navigate to the project where you want to add the classes and scaffold the client code. In this example, I will use the [SpaceX GraphQL Api](https://api.spacex.land/graphql) so run the following command:\n\n```sh\ngraphqlinq-scaffold https://api.spacex.land/graphql -o SpaceX -n SpaceX\n```\n\nThe `o` option specifies the output directory for generated classes, and `n` specifies the namespace of the classes.\n\n![Scaffolding](docs/Images/Scaffolding.gif \"Scaffolding GraphQL Client\")\n\n### Install GraphQLinq NuGet Package\n\nBefore writing the queries, you need to install the LINQ to GraphQL client library from NuGet. Run the following command to install it in the current project:\n\n```sh\ndotnet add package GraphQLinq.Client --version 1.1.0-beta\n```\n\n## Running GraphQL Queries with LINQ\n\nThe scaffolding tool generates classes for types available in the GraphQL type system and a `QueryContext` class that serves as an entry point for running the queries. GraphQLinq supports running different kinds of queries.\n\n### Query all Primitive Properties of a Type\n\nTo query all properties of a type, simply run a query like this:\n\n```cs\nvar spaceXContext = new QueryContext();\n\nvar company = await spaceXContext.Company().ToItem();\n\nRenderCompanyDetails(company);\n```\n\nThis will query all primitive and string properties of `Company`, but it won't query nested properties or collection type properties. Here is the output of the code snippet:\n\n```sh\n┌───────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────┐\n│ Property  │ Value                                                                                                    │\n├───────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────┤\n│ Name      │ SpaceX                                                                                                   │\n│ Ceo       │ Elon Musk                                                                                                │\n│ Summary   │ SpaceX designs, manufactures and launches advanced rockets and spacecraft. The company was founded in    │\n│           │ 2002 to revolutionize space technology, with the ultimate goal of enabling people to live on other       │\n│           │ planets.                                                                                                 │\n│ Founded   │ 2002                                                                                                     │\n│ Founder   │ Elon Musk                                                                                                │\n│ Employees │ 7000                                                                                                     │\n└───────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n```\n\n### Query Specific Properties\n\nIf you want to query specific properties, including a navigation property, you can specify it with the `Select` method. You either map the projection to an existing type or an anonymous object (`Headquarters` is a nested property):\n\n```cs\nvar companySummaryAnonymous = await spaceXContext.Company().Select(c =\u003e new { c.Ceo, c.Name, c.Headquarters }).ToItem();\n\n//Use data class to select specific properties\nvar companySummary = await spaceXContext.Company().Select(c =\u003e new CompanySummary\n{\n    Ceo = c.Ceo,\n    Name = c.Name,\n    Headquarters = c.Headquarters\n}).ToItem();\n\nRenderCompanySummary(companySummary);\n```\n\nThis will result in the following output:\n\n```sh\n┌──────────────┬─────────────────┐\n│ Property     │ Value           │\n├──────────────┼─────────────────┤\n│ Name         │ SpaceX          │\n│ Ceo          │ Elon Musk       │\n│ Headquarters │ ┌─────────────┐ │\n│              │ │ California  │ │\n│              │ │ Hawthorne   │ │\n│              │ │ Rocket Road │ │\n│              │ └─────────────┘ │\n└──────────────┴─────────────────┘\n```\n\n### Include Navigation Properties\n\nYou can also query navigation properties using the `Include` method. You can include several properties if you need, and you can also `Include` nested navigation properties:\n\n```cs\nvar companyWithHeadquartersAndLinks = await spaceXContext.Company()\n                                            .Include(info =\u003e info.Headquarters)\n                                            .Include(info =\u003e info.Links).ToItem();\n\nRenderCompanyDetailsAndLinks(companyWithHeadquartersAndLinks);\n```\n\n### Pass Parameters to Queries and Compose Queries\n\nIf the query has parameters, the generated method will have a parameter for each query parameter.\n\nThis code will query for all `Missions` that included **Orbital ATK** as a manufacturer. It also builds a new query over the existing one that\nincludes `Payloads` in the result.\n\n```cs\nvar missionsQuery = spaceXContext.Missions(new MissionsFind { Manufacturer = \"Orbital ATK\" }, null, null)\n                                 .Include(mission =\u003e mission.Manufacturers);\nvar missions = await missionsQuery.ToEnumerable();\n\nRenderMissions(missions);\n\nvar missionsWithPayloads = await missionsQuery.Include(mission =\u003e mission.Payloads).ToEnumerable();\n\nRenderMissions(missionsWithPayloads, true);\n```\n\n### Include Multiple Levels of Navigation Properties\n\nThe `Include` method allows quering for multi-level nested properties too. For example, here is how to query for `Launches` and include Rocket's second stage payload manufacturer:\n\n```cs\n//Launch_date_unix and Static_fire_date_unix need custom converter\nspaceXContext.JsonSerializerOptions.Converters.Add(new UnixEpochDateTimeConverter());\n\nvar launches = await spaceXContext.Launches(null, 10, 0, null, null)\n                            .Include(launch =\u003e launch.Links)\n                            .Include(launch =\u003e launch.Rocket)\n                            .Include(launch =\u003e launch.Rocket.Second_stage.Payloads.Select(payload =\u003e payload.Manufacturer))\n                            .ToEnumerable();\n\nRenderLaunches(launches);\n```\n\n### View Generated Query\n\nYou can view the GraphQL query and variables by using the `Query` and `Variables` property of the `GraphQuery` class. The `ToString()` method of the `GraphQuery` class returns the query and the variables combined:\n\n```cs\nvar missionsQuery = spaceXContext.Missions(new MissionsFind { Manufacturer = \"Orbital ATK\" }, null, null)\n                                 .Include(mission =\u003e mission.Manufacturers);\n\nvar query = missionsQuery.Query;\nvar fullQuery = missionsQuery.ToString();\n```\n\nIf you run the above code `query` will be equal to\n\n```js\nquery ($find: MissionsFind) { result: missions (find: $find) { \n  description\n  id\n  name\n  twitter\n  website\n  wikipedia\n  manufacturers\n }}\n```\n\nand the content of `fullQuery` will be:\n\n```json\n{\"query\":\"query ($find: MissionsFind) { result: missions (find: $find) { \n  description\n  id\n  name\n  twitter\n  website\n  wikipedia\n  manufacturers\n }}\",\"variables\":{\"find\":{\"manufacturer\":\"Orbital ATK\"}}}\n```\n\n## Roadmap\n\nSee the [open issues](https://github.com/Giorgi/GraphQLinq/issues) for a list of proposed features and known issues.\n\n## Contributing\n\nIf you encounter a bug or have a feature request, please use the [Issue Tracker](https://github.com/Giorgi/GraphQLinq/issues/new). The project is also open to contributions, so feel free to fork the project and open pull requests.\n\n## License\n\nCopyright © Giorgi Dalakishvili\n\nDistributed under the Apache License. See [License](License.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGiorgi%2FGraphQLinq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGiorgi%2FGraphQLinq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGiorgi%2FGraphQLinq/lists"}