Skip to content

Commit 5752b47

Browse files
committed
2 parents d54ebdd + f2365b6 commit 5752b47

File tree

1 file changed

+58
-56
lines changed

1 file changed

+58
-56
lines changed

README.md

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# FlurlGraphQL
2-
`FlurlGraphQL`` is a lightweight, simplified, asynchronous, fluent GraphQL client querying API extensions for the amazing Flurl Http library!
2+
`FlurlGraphQL` is a lightweight, simplified, asynchronous, fluent GraphQL client querying API extensions for the amazing Flurl Http library!
33

44
This makes it super easy to execute ad-hoc and simple or advanced queries against a GraphQL API such as the awesome [HotChocolate .NET GraphQL Server](https://chillicream.com/docs/hotchocolate/v13).
55

@@ -50,13 +50,13 @@ var results = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
5050
```
5151

5252
### Now Flurl v4.0+ compatible
53-
FlurlGraphQL is now fullup updated to support Flurl v4.0+ with some significant performance improvements. Just as when upgrading to Flurl v4+,
53+
FlurlGraphQL is now fully updated to support Flurl v4.0+ with some significant performance improvements. Just as when upgrading to Flurl v4+,
5454
there may be breaking changes such as those highlighted in the [Flurl upgrade docs](https://flurl.dev/docs/upgrade/).
5555

5656
#### Key Changes are:
5757
- Namespace, Project/Library, and NuGet name has now been simplified to `FlurlGraphQL` (vs `FlurlGraphQL.Querying` in v1.x).
58-
- Default Json processing now uses System.Text.Json for serialization/de-serialization.
59-
- The use of System.Text.Json brings along numerous changes associated with its use so it is best to refer to
58+
- Default Json processing now uses `System.Text.Json` for serialization/de-serialization.
59+
- The use of `System.Text.Json` brings along numerous changes associated with its use so it is best to refer to
6060
[Microsoft's migration guide here](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/migrate-from-newtonsoft?pivots=dotnet-6-0).
6161
- `System.Text.Json` processing with Json transformation strategy is now **~10X faster** than the original Newtonsoft.Json processing
6262
- The new `Newtonsoft.Json` processing has also been optimized and which now benchmarks at **~2X faster** *-- using the new Json transformation strategy (vs Converter)*.
@@ -66,24 +66,26 @@ there may be breaking changes such as those highlighted in the [Flurl upgrade do
6666
- `Newtonsoft.Json` is still fully supported but requires explicitly referencing the `FlurlGraphQL.Newtonsoft` library also available on Nuget.
6767
- To then enable `Newtonsoft.Json` processing you need to either:
6868
1. Initialize your global Flurl settings and/or clients with the out-of-the-box Flurl `NewtonsoftJsonSerializer` via Flurl Global or Request level Configuration.
69-
- Flurl Global Config Example: `clientOrRequest.Settings.JsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings())`
69+
- Flurl Global Config Example: `FlurlHttp.Clients.UseNewtonsoft();`
70+
- Flurl Request or Client level Example: `clientOrRequest.WithSettigns(settings => settings.JsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings()))...`
7071
- Doing this will automatically implement Newtonsoft processing for any/all GraphQL requests as the defautl also.
72+
- See Flurl docs for more info: [Flurl.Http.Newtonsoft](https://github.com/tmenier/Flurl/tree/dev/src/Flurl.Http.Newtonsoft#flurlhttpnewtonsoft)
7173
2. Or initialize it at the request level using the `.UseGraphQLNewtonsoftJson(...)` extension method available in ``FlurlGraphQL.Newtonsoft``.
7274
- The Json processing can always be customized/overridden at the request level for any specific GraphQL Request to use either
73-
System.Text.Json (via `.UseGraphQLSystemTextJson()`) or Newtonsoft.Json via (`.UseGraphQLNewtonsoftJson()`).
74-
- Dynamics are now only supported when using Newtonsoft.Json
75+
`System.Text.Json` (via `.UseGraphQLSystemTextJson()`) or `Newtonsoft.Json` via (`.UseGraphQLNewtonsoftJson()`).
76+
- Dynamics are now only supported when using `Newtonsoft.Json` which is consistent with Flurl v4+.
7577
- Retrieving the Raw Json responses now have dedicated APIs due to the different Json object models that each Json processing library uses.
76-
- If using System.Text.Json then you must now use the `.ReceiveGraphQLRawSystemTextJsonResponse()` method which returns a `JsonObject`.
77-
- If using Newtonsoft.Json then you must now use the `.ReceiveGraphQLRawNewtonsoftJsonResponse()` method which returns a `JObject`.
78+
- If using `System.Text.Json` then you must now use the `.ReceiveGraphQLRawSystemTextJsonResponse()` method which returns a `JsonObject`.
79+
- If using `Newtonsoft.Json` then you must now use the `.ReceiveGraphQLRawNewtonsoftJsonResponse()` method which returns a `JObject`.
7880

7981

8082
## Performance with System.Text.Json vs Newtonsoft.Json
81-
The System.Text.Json processing with Json transformation strategy is now **~10X faster** than the original Newtonsoft.Json processing.
83+
The `System.Text.Json` processing with the new Json transformation strategy is now **~10X faster** than the original `Newtonsoft.Json` processing in my tests; your results will vary and may be higher.
8284

83-
And the newly optimized Newtonsoft.Json processing with new Json transformation strategy (vs Converter) also now benchmarks **~2X faster**.
85+
And the newly optimized `Newtonsoft.Json` processing with new Json transformation strategy (vs Converter in original implementation) also now benchmarks **~2X faster**; a suprising benefit.
8486

85-
The following Benchmarks were run using .NET 6. As one might assume older versions of .NET are slower while newer versions are even faster.
86-
For example, .NET 4.6.1 is quite slow compared to .NET 6, however .NET 8 is noticeably faster.
87+
The following Benchmarks were run using .NET 6. And, as one might assume newer versions are likely even faster.
88+
For example, .NET 4.6.1 is quite slow compared to .NET 6, and .NET 8 is noticeably faster.
8789

8890
// * Benchmark.NET Summary using .NET 6 *
8991

@@ -228,15 +230,15 @@ These interfaces both expose `PageInfo` & `TotalCount` properties that may optio
228230
### Cursor Paging Example to simply retrieve a single Page...
229231

230232
Cursor paging is the approach that is strongly recommended by GraphQL.org however, offset based paging (aka CollectionSegment -
231-
*using from HotChocolate .NET GraphQL Server naming convention*)) is availble also (see below)[#offsetslice-paging-results-via-collectionsegment].
233+
*using from HotChocolate .NET GraphQL Server naming convention*)) is availble also [(see below)](#offsetslice-paging-results-via-collectionsegment).
232234

233235
```csharp
234236
var results = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
235237
.WithGraphQLQuery(@"
236238
query ($first: Int, $after: String) {
237239
characters(first: $first, after: $after) {
238240
totalCount
239-
pageInfo {
241+
pageInfo {
240242
hasNextPage
241243
hasPreviousPage
242244
startCursor
@@ -245,7 +247,7 @@ var results = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
245247
nodes {
246248
personalIdentifier
247249
name
248-
height
250+
height
249251
}
250252
}
251253
}
@@ -441,7 +443,7 @@ foreach (var pageTask in graphqlPagesTasks)
441443
```
442444

443445
### Data Models with Nested Paginated results...
444-
In GraphQL it's easy to expose nested selections of a result than itself is a paginated set of data. Thats why de-serializing this into
446+
In GraphQL it's easy to expose nested selections of a result that itself is a paginated set of data. Thats why de-serializing this into
445447
a normal model is complex and usually results in dedicated data models that are cluttered / polluted with unecessary elements such as `Nodes`, `Items`, `Edges`, or `PageInfo`, `Cursor`, etc.
446448

447449
You can still use these models if you like but in many cases with these nested data elements we primarily care about the results and
@@ -464,18 +466,18 @@ public class StarWarsCharacter
464466
var results = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
465467
.WithGraphQLQuery(@"
466468
query ($ids: [Int!], $friendsCount: Int!) {
467-
charactersById(ids: $ids) {
468-
friends(first: $friendsCount) {
469-
nodes {
470-
friends(first: $friendsCount) {
471-
nodes {
472-
name
473-
personalIdentifier
474-
}
475-
}
476-
}
469+
charactersById(ids: $ids) {
470+
friends(first: $friendsCount) {
471+
nodes {
472+
friends(first: $friendsCount) {
473+
nodes {
474+
name
475+
personalIdentifier
476+
}
477477
}
478+
}
478479
}
480+
}
479481
}
480482
")
481483
.SetGraphQLVariables(new { ids = new[] { 1000, 2001 }, friendsCount = 3 })
@@ -514,17 +516,17 @@ var json = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
514516
.WithGraphQLQuery(@"
515517
mutation ($newCharacter: Character) {
516518
characterCreateOrUpdate(input: $newCharacter) {
517-
result {
519+
result {
518520
personalIdentifier
519-
name
520-
}
521-
errors {
522-
... on Error {
523-
errorCode
524-
message
525-
}
526-
}
527-
}
521+
name
522+
}
523+
errors {
524+
... on Error {
525+
errorCode
526+
message
527+
}
528+
}
529+
}
528530
}
529531
")
530532
.SetGraphQLVariables(new { newCharacter: newCharacterModel })
@@ -548,17 +550,17 @@ Here's an example of a batch query that uses an alias to run multiple queries an
548550
var batchResults = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
549551
.WithGraphQLQuery(@"
550552
query ($first: Int) {
551-
characters(first: $first) {
553+
characters(first: $first) {
552554
nodes {
553-
personalIdentifier
554-
name
555-
height
556-
}
557-
}
555+
personalIdentifier
556+
name
557+
height
558+
}
559+
}
558560
559-
charactersCount: characters {
561+
charactersCount: characters {
560562
totalCount
561-
}
563+
}
562564
}
563565
")
564566
.SetGraphQLVariables(new { first = 2 })
@@ -589,11 +591,11 @@ var jsonObject = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
589591
query ($first: Int) {
590592
characters(first: $first) {
591593
nodes {
592-
personalIdentifier
593-
name
594-
height
595-
}
596-
}
594+
personalIdentifier
595+
name
596+
height
597+
}
598+
}
597599
}
598600
")
599601
.SetGraphQLVariables(new { first = 2 })
@@ -606,11 +608,11 @@ var jsonObject = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
606608
query ($first: Int) {
607609
characters(first: $first) {
608610
nodes {
609-
personalIdentifier
610-
name
611-
height
612-
}
613-
}
611+
personalIdentifier
612+
name
613+
height
614+
}
615+
}
614616
}
615617
")
616618
.SetGraphQLVariables(new { first = 2 })
@@ -629,7 +631,7 @@ try
629631
var json = await "https://graphql-star-wars.azurewebsites.net/api/graphql"
630632
.WithGraphQLQuery(@"
631633
query (BAD_REQUEST) {
632-
MALFORMED QUERY
634+
MALFORMED QUERY
633635
}
634636
")
635637
.PostGraphQLQueryAsync()

0 commit comments

Comments
 (0)