Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/linq2graphql/linq2graphql.client
A straightforward Linq to GraphQL Client
https://github.com/linq2graphql/linq2graphql.client
client csharp graphql graphql-client linq-to-graphql linq2graphql
Last synced: about 1 month ago
JSON representation
A straightforward Linq to GraphQL Client
- Host: GitHub
- URL: https://github.com/linq2graphql/linq2graphql.client
- Owner: Linq2GraphQL
- License: mit
- Created: 2023-10-14T09:57:28.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-02T05:00:26.000Z (about 1 month ago)
- Last Synced: 2024-10-11T13:02:39.044Z (about 1 month ago)
- Topics: client, csharp, graphql, graphql-client, linq-to-graphql, linq2graphql
- Language: C#
- Homepage: https://linq2graphql.com
- Size: 19.1 MB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Linq2GraphQL.Client
A straightforward Linq to GraphQL Client
Documentation · Report Bug · Request Feature
[![Build](https://github.com/Linq2GraphQL/Linq2GraphQL.Client/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Linq2GraphQL/Linq2GraphQL.Client/actions/workflows/ci.yml)
# Introduction
Linq2GraphQL generates C# classes from the GraphQL schema and and togheter with the nuget package Linq2GraphQL.Client it makes it possible to query the server using Linq expressions.A simple query that will get the first 10 orders with the primitive properties of orders and the connected customer.
```cs
var orders = await sampleClient
.Query
.Orders(first: 10)
.Include(e => e.Orders.Select(e => e.Customer))
.Select(e => e.Orders)
.ExecuteAsync();
```A example mutation where we add a new customer and return the Customer Id.
```cs
var customerId = await sampleClient
.Mutation
.AddCustomer(new CustomerInput
{
CustomerId = Guid.NewGuid(),
CustomerName = "New Customer",
Status = CustomerStatus.Active
})
.Select(e=> e.CustomerId)
.ExecuteAsync();
```# Getting Started
## Generate Client code
There are two options to generate the client code from the GraphQL schema.
Use the online tool to generate or install Linq2GraphQL.Generator as a tool.Install/Update Tool:
dotnet tool update Linq2GraphQL.Generator -g --prerelease
Usage:
Linq2GraphQL.Generator [options]
Arguments:
Endpoint of the GraphQL service
Options:
-o, --output Output folder, relative to current location [default: Linq2GraphQL_Generated]
-n, --namespace Namespace of generated classes [default: YourNamespace]
-c, --client Name of the generated client [default: GraphQLClient]
-t, --token Bearertoken for authentication
-s, --subscriptions Include subscriptions (Exprimental)
-es --enum-strategy If AddUnknownOption all enums will have an additional Unknown option
-nu --nullabel Nullable client [default: false]As an example:
Linq2GraphQL https://spacex-production.up.railway.app/ -c="SpaceXClient" -n="SpaceX" -o="Generated"
Would generate a client from url *https://spacex-production.up.railway.app/* with the name *SpaceXClient* in the namespace *SpaceX* to folder *Generated*
## Add Nuget
Latest stable: [![Nuget](https://img.shields.io/nuget/v/Linq2GraphQL.Client.svg)](https://www.nuget.org/packages/Linq2GraphQL.Client)
Latest prerelease: [![Nuget](https://img.shields.io/nuget/vpre/Linq2GraphQL.Client.svg)](https://www.nuget.org/packages/Linq2GraphQL.Client)dotnet add package Linq2GraphQL.Client --prerelease
## Dependency Injection
The client adds a set of extensions to make it easier to add the client to dependency injection.
As an example this would add SpaceXClient to the container:
```cs
services
.SpaceXClient(x =>
{
x.UseSafeMode = false;
})
.WithHttpClient(
httpClient =>
{
httpClient.BaseAddress = new Uri("https://spacex-production.up.railway.app/");
});
```
## Safe Mode
Turning on *SafeMode* will make the client before the first request to do an introspection query to the endpoint. The schema will be used to make sure that any auto included properties are available. This is an advanced feature that require the endpoint to support introspection. By default safe mode is turned of.# Acknowledgments
Linq2GraphQL is inspired by [GraphQLinq](https://github.com/Giorgi/GraphQLinq) , thank you [Giorgi](https://github.com/Giorgi)[![Stargazers repo roster for @linq2graphql/linq2graphql.client](https://reporoster.com/stars/dark/linq2graphql/linq2graphql.client)](https://github.com/linq2graphql/linq2graphql.client/stargazers)