Skip to content

Commit d963398

Browse files
committed
added SelectMany
more docs
1 parent 9dde477 commit d963398

8 files changed

Lines changed: 76 additions & 21 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@inherits SampleBase;
2+
3+
4+
<SamplesViewer Title="Select many" QueryExecute="GetQuery()" TypeFullName="@GetTypeFullName()" >
5+
6+
7+
</SamplesViewer>
8+
9+
10+
11+
12+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Linq2GraphQL.Client;
2+
namespace Linq2GraphQL.Docs.Components.Samples.Queries
3+
{
4+
public partial class SelectMany
5+
{
6+
private GraphCursorQueryExecute<StarWars.Client.FilmsConnection, IEnumerable<string>> GetQuery()
7+
{
8+
return starWarsClient
9+
.Query
10+
.AllFilms()
11+
.Select(e => e.Films.SelectMany(e => e.Producers)
12+
);
13+
}
14+
}
15+
}

docs/Linq2GraphQL.Docs/Components/Samples/Samples.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
<Linq2GraphQL.Docs.Components.Samples.Queries.BasicQuery />
12-
1312
<Linq2GraphQL.Docs.Components.Samples.Queries.ProjectCustomObject />
13+
<Linq2GraphQL.Docs.Components.Samples.Queries.SelectMany />
1414

1515

docs/Linq2GraphQL.Docs/Components/Samples/SamplesViewer.razor

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@typeparam TResult
33

44

5-
<Card class="mb-3" Size="CardSize.Small">
5+
<Card id="@id" class="mb-3" Size="CardSize.Small">
66
<CardBody>
77

88

@@ -13,44 +13,44 @@
1313
</div>
1414

1515

16-
<div>
16+
<div style="max-height:200px">
1717
@((MarkupString)queryHtml)
1818
</div>
1919

2020
@if (isExpanded)
2121
{
2222
<Tabs @ref=tabs>
23-
<Tab Title="Request">
24-
25-
<div style="height:300px">
26-
<StandaloneCodeEditor Id="@(id + "_request")" ConstructionOptions="RequestConstructionOptions" />
27-
</div>
28-
29-
</Tab>
23+
3024
<Tab Title="Query">
3125
<div style="height:300px">
3226
<StandaloneCodeEditor Id="@(id + "_query")" ConstructionOptions="QueryConstructionOptions" />
3327
</div>
3428
</Tab>
3529

30+
<Tab Title="Variables">
31+
<div style="height:300px">
32+
<StandaloneCodeEditor Id="@(id + "_variables")" ConstructionOptions="VariableConstructionOptions" />
33+
</div>
34+
</Tab>
3635

37-
<Tab Title="Base Result">
36+
<Tab Title="Result">
3837
<Header>
3938
@if (QueryExecute.BaseResult == null)
4039
{
4140
<Button Disabled=isExecuting Size=ButtonSize.Small BackgroundColor=TablerColor.Primary OnClick="ExecuteAsync">Execute</Button>
4241
}
4342
else
4443
{
45-
<span>Base Result</span>
44+
<span>Result</span>
4645
}
4746

4847
</Header>
4948
<ChildContent>
5049
<div style="height:300px">
5150
@if (QueryExecute.BaseResult != null)
5251
{
53-
<StandaloneCodeEditor Id="@(id + "_response")" ConstructionOptions="ResponseConstructionOptions" />
52+
<StandaloneCodeEditor Id="@(id + "_result")" ConstructionOptions="ResultConstructionOptions" />
53+
5454
}
5555
</div>
5656
</ChildContent>
@@ -59,9 +59,10 @@
5959

6060
@if (QueryExecute.BaseResult != null)
6161
{
62-
<Tab Title="Result">
62+
<Tab Title="Base Result">
6363
<div style="height:300px">
64-
<StandaloneCodeEditor Id="@(id + "_result")" ConstructionOptions="ResultConstructionOptions" />
64+
<StandaloneCodeEditor Id="@(id + "_baseResult")" ConstructionOptions="ResponseConstructionOptions" />
65+
6566
</div>
6667
</Tab>
6768
}

docs/Linq2GraphQL.Docs/Components/Samples/SamplesViewer.razor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text.Json;
66
using TabBlazor;
77
using StarWars.Client;
8+
using TabBlazor.Services;
89

910
namespace Linq2GraphQL.Docs.Components.Samples
1011
{
@@ -14,6 +15,7 @@ public partial class SamplesViewer<T, TResult>
1415
private string requestJson;
1516

1617
[Inject] private HttpClient httpClient { get; set; }
18+
[Inject] private TablerService tablerService { get; set; }
1719

1820
[Parameter] public GraphQueryExecute<T, TResult> QueryExecute { get; set; }
1921
[Parameter] public string TypeFullName { get; set; }
@@ -83,11 +85,11 @@ private string Wrap(string source, string keyword, string cssClass)
8385
return source.Replace(keyword, $@"<span class=""{cssClass}"">{keyword}</span>");
8486
}
8587

86-
87-
8888
private async Task ShowDetailsAsync()
8989
{
9090
isExpanded = !isExpanded;
91+
await Task.Yield();
92+
await tablerService.ScrollToFragment(id);
9193
}
9294

9395

@@ -113,13 +115,13 @@ private async Task ExecuteAsync()
113115
}
114116
}
115117

116-
private StandaloneEditorConstructionOptions RequestConstructionOptions(StandaloneCodeEditor editor)
118+
private StandaloneEditorConstructionOptions VariableConstructionOptions(StandaloneCodeEditor editor)
117119
{
118120
return new StandaloneEditorConstructionOptions
119121
{
120122
AutomaticLayout = true,
121123
Language = "json",
122-
Value = requestJson,
124+
Value = JsonSerializer.Serialize(request.Variables, jsonOptions),
123125
WordWrap = "on"
124126
};
125127
}

src/Linq2GraphQL.Client/Utilities.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ namespace Linq2GraphQL.Client;
55

66
public static class Utilities
77
{
8+
public static bool IsSelectOrSelectMany(this MethodCallExpression methodCallExpression)
9+
{
10+
if (methodCallExpression.Arguments.Count != 2) { return false; };
11+
12+
var methodName = methodCallExpression.Method.Name;
13+
14+
return (methodName == "Select" || methodName == "SelectMany");
15+
16+
17+
}
18+
819
public static void ParseExpression(Expression body, QueryNode parent)
920
{
1021
var node = new QueryNode(parent.Member);
@@ -24,7 +35,7 @@ private static void ParseExpressionInternal(Expression body, QueryNode parent)
2435
{
2536
var exp = (MemberInitExpression)body;
2637

27-
foreach (MemberAssignment bining in exp.Bindings.Where(e => e.BindingType == MemberBindingType.Assignment))
38+
foreach (MemberAssignment bining in exp.Bindings.Where(e => e.BindingType == MemberBindingType.Assignment).Cast<MemberAssignment>())
2839
{
2940
ParseExpressionInternal(bining.Expression, parent);
3041
}
@@ -99,7 +110,7 @@ private static void ParseMethodCallExpression(QueryNode parent, MethodCallExpres
99110
parent.AddChildNode(queryNode);
100111

101112
}
102-
else if (methodCallExp.Method.Name == "Select" && methodCallExp.Arguments.Count == 2)
113+
else if (methodCallExp.IsSelectOrSelectMany())
103114
{
104115
if (methodCallExp.Arguments[0] is MemberExpression memberExpr)
105116
{

test/Linq2GraphQL.Tests/MutationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public async Task Mutation_Multiple()
3535
{
3636
CustomerId = id,
3737
CustomerName = "New Customer",
38+
Orders = new List<OrderInput>(),
3839
Status = CustomerStatus.Active
3940
})
4041
.Select(e=> e.CustomerId)

test/Linq2GraphQL.Tests/QueryProjectionTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ public async Task ProjectingToType()
5252

5353
}
5454

55+
[Fact]
56+
public async Task Project_SelectMany()
57+
{
58+
var query = sampleClient
59+
.Query
60+
.Customers()
61+
.Select(e => e.SelectMany(e=> e.Orders));
62+
63+
// var request = await query.GetRequestAsync();
64+
var result = await query.ExecuteAsync();
65+
66+
67+
}
5568

5669

5770

0 commit comments

Comments
 (0)