Skip to content

Commit 1a29146

Browse files
committed
fix controller post
1 parent 506b232 commit 1a29146

4 files changed

Lines changed: 77 additions & 2 deletions

File tree

docs/configuration.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ public class GraphQlController :
259259
return Execute(query, operationName, inputs, cancellation);
260260
}
261261

262+
[HttpPost]
263+
public Task Post(
264+
[FromQuery] string query,
265+
[FromQuery] string? variables,
266+
[FromQuery] string? operationName,
267+
CancellationToken cancellation)
268+
{
269+
var inputs = variables.ToInputs();
270+
return Execute(query, operationName, inputs, cancellation);
271+
}
272+
262273
async Task Execute(string query,
263274
string? operationName,
264275
Inputs? variables,
@@ -282,7 +293,7 @@ public class GraphQlController :
282293
}
283294
}
284295
```
285-
<sup><a href='/src/SampleWeb/GraphQlController.cs#L6-L55' title='Snippet source file'>snippet source</a> | <a href='#snippet-graphqlcontroller' title='Start of snippet'>anchor</a></sup>
296+
<sup><a href='/src/SampleWeb/GraphQlController.cs#L6-L66' title='Snippet source file'>snippet source</a> | <a href='#snippet-graphqlcontroller' title='Start of snippet'>anchor</a></sup>
286297
<!-- endSnippet -->
287298

288299

@@ -450,6 +461,21 @@ public class GraphQlControllerTests
450461
await Verify(await response.Content.ReadAsStringAsync());
451462
}
452463

464+
[Fact]
465+
public async Task Post()
466+
{
467+
var query = @"
468+
{
469+
companies
470+
{
471+
id
472+
}
473+
}";
474+
using var response = await clientQueryExecutor.ExecutePost(client, query);
475+
response.EnsureSuccessStatusCode();
476+
await Verify(await response.Content.ReadAsStringAsync());
477+
}
478+
453479
[Fact]
454480
public async Task Single()
455481
{
@@ -584,7 +610,7 @@ query {
584610
}
585611
}
586612
```
587-
<sup><a href='/src/SampleWeb.Tests/GraphQlControllerTests.cs#L7-L179' title='Snippet source file'>snippet source</a> | <a href='#snippet-graphqlcontrollertests' title='Start of snippet'>anchor</a></sup>
613+
<sup><a href='/src/SampleWeb.Tests/GraphQlControllerTests.cs#L7-L194' title='Snippet source file'>snippet source</a> | <a href='#snippet-graphqlcontrollertests' title='Start of snippet'>anchor</a></sup>
588614
<!-- endSnippet -->
589615

590616

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"data": {
3+
"companies": [
4+
{
5+
"id": 1
6+
},
7+
{
8+
"id": 4
9+
},
10+
{
11+
"id": 6
12+
},
13+
{
14+
"id": 7
15+
}
16+
]
17+
}
18+
}

src/SampleWeb.Tests/GraphQlControllerTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ public async Task Get()
4242
await Verify(await response.Content.ReadAsStringAsync());
4343
}
4444

45+
[Fact]
46+
public async Task Post()
47+
{
48+
var query = @"
49+
{
50+
companies
51+
{
52+
id
53+
}
54+
}";
55+
using var response = await clientQueryExecutor.ExecutePost(client, query);
56+
response.EnsureSuccessStatusCode();
57+
await Verify(await response.Content.ReadAsStringAsync());
58+
}
59+
4560
[Fact]
4661
public async Task Single()
4762
{

src/SampleWeb/GraphQlController.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ public Task Get(
3030
return Execute(query, operationName, inputs, cancellation);
3131
}
3232

33+
public class GraphQLQuery
34+
{
35+
public string? OperationName { get; set; }
36+
public string Query { get; set; }= null!;
37+
public string? Variables { get; set; }
38+
}
39+
40+
[HttpPost]
41+
public Task Post(
42+
[FromBody]GraphQLQuery query,
43+
CancellationToken cancellation)
44+
{
45+
var inputs = query.Variables.ToInputs();
46+
return Execute(query.Query, query.OperationName, inputs, cancellation);
47+
}
48+
3349
async Task Execute(string query,
3450
string? operationName,
3551
Inputs? variables,

0 commit comments

Comments
 (0)