| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c6452e1 commit bb88224
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ then I do love-me-some-coffee!* | |||
| 32 | 32 | var results = await "https://graphql-star-wars.azurewebsites.net/api/graphql" | |
| 33 | 33 | .WithGraphQLQuery(@" | |
| 34 | 34 | query ($ids: [Int!], $friendsCount: Int!) { | |
| 35 | - charactersById(ids: $ids) { | ||
| 35 | + charactersById(ids: $ids) { | ||
| 36 | 36 | personalIdentifier | |
| 37 | 37 | name | |
| 38 | 38 | friends(first: $friendsCount) { | |
@@ -484,28 +484,32 @@ public class StarWarsCharacter | |||
| 484 | 484 | var results = await "https://graphql-star-wars.azurewebsites.net/api/graphql" | |
| 485 | 485 | .WithGraphQLQuery(@" | |
| 486 | 486 | query ($ids: [Int!], $friendsCount: Int!) { | |
| 487 | - charactersById(ids: $ids) { | ||
| 488 | - friends(first: $friendsCount) { | ||
| 489 | - nodes { | ||
| 490 | - friends(first: $friendsCount) { | ||
| 491 | - nodes { | ||
| 492 | - name | ||
| 493 | - personalIdentifier | ||
| 494 | - } | ||
| 495 | - } | ||
| 496 | - } | ||
| 487 | + charactersById(ids: $ids) { | ||
| 488 | + name | ||
| 489 | + personalIdentifier | ||
| 490 | + friends(first: $friendsCount) { | ||
| 491 | + nodes { | ||
| 492 | + name | ||
| 493 | + personalIdentifier | ||
| 494 | + friends(first: $friendsCount) { | ||
| 495 | + nodes { | ||
| 496 | + name | ||
| 497 | + personalIdentifier | ||
| 498 | + } | ||
| 499 | + } | ||
| 500 | + } | ||
| 501 | + } | ||
| 497 | 502 | } | |
| 498 | - } | ||
| 499 | 503 | } | |
| 500 | 504 | ") | |
| 501 | 505 | .SetGraphQLVariables(new { ids = new[] { 1000, 2001 }, friendsCount = 3 }) | |
| 502 | 506 | .PostGraphQLQueryAsync() | |
| 503 | 507 | .ReceiveGraphQLQueryResults<StarWarsCharacter>(); | |
| 504 | 508 | ||
| 505 | - foreach (var result in results) | ||
| 509 | + foreach (var character in results) | ||
| 506 | 510 | { | |
| 507 | 511 | //... process each of the 2 initial results by Id... | |
| 508 | - foreach (var friend in result.Friends) | ||
| 512 | + foreach (var friend in character.Friends) | ||
| 509 | 513 | { | |
| 510 | 514 | //... process each of the nested friend results, but without the need for | |
| 511 | 515 | // our Model to be complicated by the fact that this is a paginated result from GraphQL... | |
@@ -536,15 +540,15 @@ var json = await "https://graphql-star-wars.azurewebsites.net/api/graphql" | |||
| 536 | 540 | characterCreateOrUpdate(input: $newCharacter) { | |
| 537 | 541 | result { | |
| 538 | 542 | personalIdentifier | |
| 539 | - name | ||
| 540 | - } | ||
| 541 | - errors { | ||
| 542 | - ... on Error { | ||
| 543 | - errorCode | ||
| 544 | - message | ||
| 545 | - } | ||
| 546 | - } | ||
| 547 | - } | ||
| 543 | + name | ||
| 544 | + } | ||
| 545 | + errors { | ||
| 546 | + ... on Error { | ||
| 547 | + errorCode | ||
| 548 | + message | ||
| 549 | + } | ||
| 550 | + } | ||
| 551 | + } | ||
| 548 | 552 | } | |
| 549 | 553 | ") | |
| 550 | 554 | .SetGraphQLVariables(new { newCharacter: newCharacterModel }) | |
@@ -570,15 +574,14 @@ var batchResults = await "https://graphql-star-wars.azurewebsites.net/api/graphq | |||
| 570 | 574 | query ($first: Int) { | |
| 571 | 575 | characters(first: $first) { | |
| 572 | 576 | nodes { | |
| 573 | - personalIdentifier | ||
| 574 | - name | ||
| 575 | - height | ||
| 576 | - } | ||
| 577 | - } | ||
| 578 | - | ||
| 579 | - charactersCount: characters { | ||
| 577 | + personalIdentifier | ||
| 578 | + name | ||
| 579 | + height | ||
| 580 | + } | ||
| 581 | + } | ||
| 582 | + charactersCount: characters { | ||
| 580 | 583 | totalCount | |
| 581 | - } | ||
| 584 | + } | ||
| 582 | 585 | } | |
| 583 | 586 | ") | |
| 584 | 587 | .SetGraphQLVariables(new { first = 2 }) | |
@@ -598,39 +601,38 @@ You can always request the raw Json response that was returned by the GraphQL se | |||
| 598 | 601 | Simply use the respective API based on if you want are using System.Text.Json (via `.ReceiveGraphQLRawSystemTextJsonResponse()`) | |
| 599 | 602 | or Newtonsoft.Json (via `.ReceiveGraphQLRawNewtonsoftJsonResponse()`). | |
| 600 | 603 | ||
| 601 | - *NOTE: You cannot receive `Newtonsoft.Json` raw json if the request was initialzied and executing using `System.Text.Json` serailizer and vice-versa; | ||
| 604 | + *NOTE: You cannot receive `Newtonsoft.Json` raw json if the request was initialzied and executing using the `System.Text.Json` serailizer and vice-versa; | ||
| 602 | 605 | a runtime exception will be thrown becuase this would be a large performance impact that would likely go unnoticed if it was allowed.* | |
| 603 | 606 | ||
| 604 | 607 | ```csharp | |
| 605 | - | ||
| 606 | 608 | //For System.Text.Json Raw GraphQL response processing you will get a `JsonObject` result back for RAW Json handling! | |
| 607 | 609 | var jsonObject = await "https://graphql-star-wars.azurewebsites.net/api/graphql" | |
| 608 | 610 | .WithGraphQLQuery(@" | |
| 609 | 611 | query ($first: Int) { | |
| 610 | 612 | characters(first: $first) { | |
| 611 | 613 | nodes { | |
| 612 | - personalIdentifier | ||
| 613 | - name | ||
| 614 | - height | ||
| 615 | - } | ||
| 616 | - } | ||
| 614 | + personalIdentifier | ||
| 615 | + name | ||
| 616 | + height | ||
| 617 | + } | ||
| 618 | + } | ||
| 617 | 619 | } | |
| 618 | 620 | ") | |
| 619 | 621 | .SetGraphQLVariables(new { first = 2 }) | |
| 620 | 622 | .PostGraphQLQueryAsync() | |
| 621 | 623 | .ReceiveGraphQLRawSystemTextJsonResponse(); | |
| 622 | 624 | ||
| 623 | 625 | //OR For Newtonsoft.Json Raw GraphQL response processing you will get a `JObject` result back (just as with v1.x) for RAW Json handling! | |
| 624 | - var jsonObject = await "https://graphql-star-wars.azurewebsites.net/api/graphql" | ||
| 626 | + var jObject = await "https://graphql-star-wars.azurewebsites.net/api/graphql" | ||
| 625 | 627 | .WithGraphQLQuery(@" | |
| 626 | 628 | query ($first: Int) { | |
| 627 | 629 | characters(first: $first) { | |
| 628 | 630 | nodes { | |
| 629 | - personalIdentifier | ||
| 630 | - name | ||
| 631 | - height | ||
| 632 | - } | ||
| 633 | - } | ||
| 631 | + personalIdentifier | ||
| 632 | + name | ||
| 633 | + height | ||
| 634 | + } | ||
| 635 | + } | ||
| 634 | 636 | } | |
| 635 | 637 | ") | |
| 636 | 638 | .SetGraphQLVariables(new { first = 2 }) | |
@@ -676,7 +678,7 @@ the `JsonDefaults` enum flags that can be set on the default configuration using | |||
| 676 | 678 | - `EnableScreamingCaseEnums` -- Ensures that Enum strings are automatically converted to SCREAMING_CASE as is the default for GraphQL enums (e.g. HotChocolate GraphQL Server). | |
| 677 | 679 | - This has no effect if the above `EnableStringEnumHandling` is disabled; unless you manually implement the screaming case naming policies/strategy (e.g. `FlurlGraphQLSystemTextJsonScreamingCaseNamingPolicy`). | |
| 678 | 680 | - `EnableCamelCaseSerialization` -- Ensures that the Json serialization is compatible with GraphQL JSON conventions which use camelCase and are usually case sensitive (e.g. HotChocolate GraphQL Server). | |
| 679 | - - `EnableCaseInsensitiveJsonHandling` -- Ensures that Json de-serialziation is not case sensitive because C# conventions for `PascalCase` will nearly always fail due to JSON conventions for `camelCase`. | ||
| 681 | + - `EnableCaseInsensitiveJsonHandling` -- Ensures that Json de-serialziation is not case sensitive because otherwise C# conventions for `PascalCase` will nearly always fail due to JSON conventions for `camelCase`. | ||
| 680 | 682 | - NOTE: This *ONLY* applies to `System.Text.Json` because case-insensitive matching cannot be disabled with `Newtonsoft.Json`. | |
| 681 | 683 | - `EnableAll` -- a convenience flag used by default to ensure all of the above are enabled to greatly simplify the common pitfalls for Json handlingw between C# & GraphQL. | |
| 682 | 684 | ||
@@ -689,6 +691,7 @@ and how the response is parsed when being de-serailized back into your model.* | |||
| 689 | 691 | ```csharp | |
| 690 | 692 | //Control how default Json Options/Settings are initialzied (for either System.Text.Json or Newtonsoft) | |
| 691 | 693 | //NOTE: If Enabled, these global GraphQL Defaults will be enforced on any settings specified, even at the Request level. | |
| 694 | + //NOTE: These are usually be set in your program.cs or other bootstrapping code on application startup. | ||
| 692 | 695 | FlurlGraphQLConfig.ConfigureDefaults(config => | |
| 693 | 696 | { | |
| 694 | 697 | config.JsonProcessingDefaults = JsonDefaults.EnableAll; | |
@@ -707,7 +710,7 @@ and how the response is parsed when being de-serailized back into your model.* | |||
| 707 | 710 | PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | |
| 708 | 711 | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, | |
| 709 | 712 | WriteIndented = true, | |
| 710 | - //NOTE: THIS settings will not actually have any effect as the Framework always switches it ON to enable `case insensitive` processing. | ||
| 713 | + //NOTE: THIS settings will not actually have any effect as the FlurlGraphQL framework always switches it ON to enable `case insensitive` processing. | ||
| 711 | 714 | // This is due to the fact that GraphQL Json and C# often have different naming conventions for the Json so the vast majority of requests | |
| 712 | 715 | // would fail if not enabled automatically! | |
| 713 | 716 | PropertyNameCaseInsensitive = true | |
| Back | FazBrowse Home | New Git URL |
0 commit comments