Skip to content

Commit

Permalink
Update README and add to solution
Browse files Browse the repository at this point in the history
The README.md file has been updated to improve code snippet readability and include new badges. Additionally, the README file has been added to the Linq2GraphQL solution for easier access.
  • Loading branch information
Magnus Ahlberg committed Feb 2, 2024
1 parent 744411a commit 31249a8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
1 change: 1 addition & 0 deletions Linq2GraphQL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".items", ".items", "{7A8567
Directory.Build.props = Directory.Build.props
nuget.config = nuget.config
version.json = version.json
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Linq2GraphQL.TestServer", "test\Linq2GraphQL.TestServer\Linq2GraphQL.TestServer.csproj", "{AD8291B6-5979-4C43-B785-EAD4FF93C564}"
Expand Down
52 changes: 30 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,37 @@
<p>A straightforward Linq to GraphQL Client</p>

<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>

[![Build](https://github.com/Linq2GraphQL/Linq2GraphQL.Client/actions/workflows/ci.yml/badge.svg)](hhttps://github.com/Linq2GraphQL/Linq2GraphQL.Client/actions/workflows/ci.yml?branch=master)

</div>

# 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.

var orders = await sampleClient
.Query
```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.

var customerId = await sampleClient
.Mutation
.AddCustomer(new CustomerInput
{
CustomerId = Guid.NewGuid(),
CustomerName = "New Customer",
Status = CustomerStatus.Active
})
.Select(e=> e.CustomerId)
.ExecuteAsync();
```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
Expand Down Expand Up @@ -65,23 +69,27 @@ As an example:
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
Add the Nuget Package [Linq2GraphQL.Client](https://www.nuget.org/packages/Linq2GraphQL.Client)
Add the Nuget Package [![Nuget](https://img.shields.io/nuget/v/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:

services.SpaceXClient(x =>
```cs
services
.SpaceXClient(x =>
{
x.UseSafeMode = false;
})
.WithHttpClient(
httpClient => { httpClient.BaseAddress = new Uri("https://spacex-production.up.railway.app/"); });

.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.
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)
Expand Down

0 comments on commit 31249a8

Please sign in to comment.