@@ -65,7 +65,7 @@ public virtual async Task InvokeAsync(HttpContext context, RequestDelegate next)
65
65
66
66
// Parse POST body
67
67
GraphQLRequest bodyGQLRequest = null ;
68
- GraphQLRequest [ ] bodyGQLBatchRequest = null ;
68
+ IList < GraphQLRequest > bodyGQLBatchRequest = null ;
69
69
if ( isPost )
70
70
{
71
71
if ( ! MediaTypeHeaderValue . TryParse ( httpRequest . ContentType , out var mediaTypeHeader ) )
@@ -77,7 +77,7 @@ public virtual async Task InvokeAsync(HttpContext context, RequestDelegate next)
77
77
switch ( mediaTypeHeader . MediaType )
78
78
{
79
79
case MediaType . JSON :
80
- GraphQLRequest [ ] deserializationResult ;
80
+ IList < GraphQLRequest > deserializationResult ;
81
81
try
82
82
{
83
83
#if NET5_0_OR_GREATER
@@ -90,14 +90,14 @@ public virtual async Task InvokeAsync(HttpContext context, RequestDelegate next)
90
90
if ( sourceEncoding != null && sourceEncoding != System . Text . Encoding . UTF8 )
91
91
{
92
92
using var tempStream = System . Text . Encoding . CreateTranscodingStream ( httpRequest . Body , innerStreamEncoding : sourceEncoding , outerStreamEncoding : System . Text . Encoding . UTF8 , leaveOpen : true ) ;
93
- deserializationResult = await _serializer . ReadAsync < GraphQLRequest [ ] > ( tempStream , cancellationToken ) ;
93
+ deserializationResult = await _serializer . ReadAsync < IList < GraphQLRequest > > ( tempStream , cancellationToken ) ;
94
94
}
95
95
else
96
96
{
97
- deserializationResult = await _serializer . ReadAsync < GraphQLRequest [ ] > ( httpRequest . Body , cancellationToken ) ;
97
+ deserializationResult = await _serializer . ReadAsync < IList < GraphQLRequest > > ( httpRequest . Body , cancellationToken ) ;
98
98
}
99
99
#else
100
- deserializationResult = await _serializer . ReadAsync < GraphQLRequest [ ] > ( httpRequest . Body , cancellationToken ) ;
100
+ deserializationResult = await _serializer . ReadAsync < IList < GraphQLRequest > > ( httpRequest . Body , cancellationToken ) ;
101
101
#endif
102
102
}
103
103
catch ( Exception ex )
@@ -106,7 +106,8 @@ public virtual async Task InvokeAsync(HttpContext context, RequestDelegate next)
106
106
throw ;
107
107
return ;
108
108
}
109
- if ( deserializationResult ? . Length == 1 )
109
+ // https://github.com/graphql-dotnet/server/issues/751
110
+ if ( deserializationResult is GraphQLRequest [ ] array && array . Length == 1 )
110
111
bodyGQLRequest = deserializationResult [ 0 ] ;
111
112
else
112
113
bodyGQLBatchRequest = deserializationResult ;
@@ -172,7 +173,7 @@ protected virtual async Task HandleRequestAsync(
172
173
HttpContext context ,
173
174
RequestDelegate next ,
174
175
IDictionary < string , object > userContext ,
175
- GraphQLRequest [ ] bodyGQLBatchRequest ,
176
+ IList < GraphQLRequest > bodyGQLBatchRequest ,
176
177
GraphQLRequest gqlRequest ,
177
178
IGraphQLExecuter < TSchema > executer ,
178
179
CancellationToken cancellationToken )
@@ -191,8 +192,8 @@ protected virtual async Task HandleRequestAsync(
191
192
// Execute multiple graphql requests in one batch
192
193
else
193
194
{
194
- var executionResults = new ExecutionResult [ bodyGQLBatchRequest . Length ] ;
195
- for ( int i = 0 ; i < bodyGQLBatchRequest . Length ; ++ i )
195
+ var executionResults = new ExecutionResult [ bodyGQLBatchRequest . Count ] ;
196
+ for ( int i = 0 ; i < bodyGQLBatchRequest . Count ; ++ i )
196
197
{
197
198
var gqlRequestInBatch = bodyGQLBatchRequest [ i ] ;
198
199
0 commit comments