11
11
using System . Collections . Generic ;
12
12
using System . IO ;
13
13
using System . Net . Http . Headers ;
14
+ using System . Threading ;
14
15
using System . Threading . Tasks ;
15
16
16
17
namespace GraphQL . Server . Transports . AspNetCore
@@ -99,6 +100,7 @@ public async Task InvokeAsync(HttpContext context)
99
100
userContext = new Dictionary < string , object > ( ) ; // in order to allow resolvers to exchange their state through this object
100
101
101
102
var executer = context . RequestServices . GetRequiredService < IGraphQLExecuter < TSchema > > ( ) ;
103
+ var token = GetCancellationToken ( context ) ;
102
104
103
105
// normal execution with single graphql request
104
106
if ( gqlBatchRequest == null )
@@ -109,7 +111,7 @@ public async Task InvokeAsync(HttpContext context)
109
111
gqlRequest . Query ,
110
112
gqlRequest . GetInputs ( ) ,
111
113
userContext ,
112
- context . RequestAborted ) . ConfigureAwait ( false ) ;
114
+ token ) . ConfigureAwait ( false ) ;
113
115
114
116
await RequestExecutedAsync ( new GraphQLRequestExecutionResult ( gqlRequest , result , stopwatch . Elapsed ) ) ;
115
117
@@ -129,7 +131,7 @@ public async Task InvokeAsync(HttpContext context)
129
131
request . Query ,
130
132
request . GetInputs ( ) ,
131
133
userContext ,
132
- context . RequestAborted ) . ConfigureAwait ( false ) ;
134
+ token ) . ConfigureAwait ( false ) ;
133
135
134
136
await RequestExecutedAsync ( new GraphQLRequestExecutionResult ( gqlRequest , result , stopwatch . Elapsed , i ) ) ;
135
137
@@ -140,6 +142,8 @@ public async Task InvokeAsync(HttpContext context)
140
142
}
141
143
}
142
144
145
+ protected virtual CancellationToken GetCancellationToken ( HttpContext context ) => context . RequestAborted ;
146
+
143
147
protected virtual Task RequestExecutedAsync ( in GraphQLRequestExecutionResult requestExecutionResult )
144
148
{
145
149
// nothing to do in this middleware
0 commit comments