|
7 | 7 | <p>A straightforward Linq to GraphQL Client</p> |
8 | 8 |
|
9 | 9 | <h4> <a href="https://linq2graphql.com"> Documentation </a> <span> · </span> <a href="https://github.com/Linq2GraphQL/Linq2GraphQL.Client/issues"> Report Bug </a> <span> · </span> <a href="https://github.com/Linq2GraphQL/Linq2GraphQL.Client/issues"> Request Feature </a> </h4> |
| 10 | + |
| 11 | +[](hhttps://github.com/Linq2GraphQL/Linq2GraphQL.Client/actions/workflows/ci.yml?branch=master) |
| 12 | + |
10 | 13 | </div> |
11 | 14 |
|
12 | 15 | # Introduction |
13 | 16 | 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. |
14 | 17 |
|
15 | 18 | A simple query that will get the first 10 orders with the primitive properties of orders and the connected customer. |
16 | | - |
17 | | - var orders = await sampleClient |
18 | | - .Query |
| 19 | +```cs |
| 20 | +var orders = await sampleClient |
| 21 | + .Query |
19 | 22 | .Orders(first: 10) |
20 | 23 | .Include(e => e.Orders.Select(e => e.Customer)) |
21 | 24 | .Select(e => e.Orders) |
22 | 25 | .ExecuteAsync(); |
| 26 | +``` |
23 | 27 |
|
24 | 28 | A example mutation where we add a new customer and return the Customer Id. |
25 | | - |
26 | | - var customerId = await sampleClient |
27 | | - .Mutation |
28 | | - .AddCustomer(new CustomerInput |
29 | | - { |
30 | | - CustomerId = Guid.NewGuid(), |
31 | | - CustomerName = "New Customer", |
32 | | - Status = CustomerStatus.Active |
33 | | - }) |
34 | | - .Select(e=> e.CustomerId) |
35 | | - .ExecuteAsync(); |
36 | | - |
| 29 | +```cs |
| 30 | + var customerId = await sampleClient |
| 31 | + .Mutation |
| 32 | + .AddCustomer(new CustomerInput |
| 33 | + { |
| 34 | + CustomerId = Guid.NewGuid(), |
| 35 | + CustomerName = "New Customer", |
| 36 | + Status = CustomerStatus.Active |
| 37 | + }) |
| 38 | + .Select(e=> e.CustomerId) |
| 39 | + .ExecuteAsync(); |
| 40 | +``` |
37 | 41 |
|
38 | 42 | # Getting Started |
39 | 43 | ## Generate Client code |
@@ -65,23 +69,27 @@ As an example: |
65 | 69 | Would generate a client from url *https://spacex-production.up.railway.app/* with the name *SpaceXClient* in the namespace *SpaceX* to folder *Generated* |
66 | 70 |
|
67 | 71 | ## Add Nuget |
68 | | -Add the Nuget Package [Linq2GraphQL.Client](https://www.nuget.org/packages/Linq2GraphQL.Client) |
| 72 | +Add the Nuget Package [](https://www.nuget.org/packages/Linq2GraphQL.Client) |
69 | 73 |
|
70 | 74 | dotnet add package Linq2GraphQL.Client --prerelease |
71 | 75 |
|
72 | 76 | ## Dependency Injection |
73 | 77 | The client adds a set of extensions to make it easier to add the client to dependency injection. |
74 | 78 | As an example this would add SpaceXClient to the container: |
75 | | - |
76 | | - services.SpaceXClient(x => |
| 79 | +```cs |
| 80 | +services |
| 81 | + .SpaceXClient(x => |
77 | 82 | { |
78 | 83 | x.UseSafeMode = false; |
79 | 84 | }) |
80 | | - .WithHttpClient( |
81 | | - httpClient => { httpClient.BaseAddress = new Uri("https://spacex-production.up.railway.app/"); }); |
82 | | - |
| 85 | + .WithHttpClient( |
| 86 | + httpClient => |
| 87 | + { |
| 88 | + httpClient.BaseAddress = new Uri("https://spacex-production.up.railway.app/"); |
| 89 | + }); |
| 90 | +``` |
83 | 91 | ## Safe Mode |
84 | | -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. |
| 92 | +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. |
85 | 93 |
|
86 | 94 | # Acknowledgments |
87 | 95 | Linq2GraphQL is inspired by [GraphQLinq](https://github.com/Giorgi/GraphQLinq) , thank you [Giorgi](https://github.com/Giorgi) |
|
0 commit comments