Skip to content

Commit 1dbe2a7

Browse files
SimonCroppjoemcbride
authored andcommitted
Make use of ConfigureAwait(false) consistent (graphql-dotnet#1263)
1 parent 107c1f8 commit 1dbe2a7

15 files changed

+31
-31
lines changed

src/GraphQL/DataLoader/BatchDataLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task<T> LoadAsync(TKey key)
6868
}
6969
}
7070

71-
var result = await DataLoaded;
71+
var result = await DataLoaded.ConfigureAwait(false);
7272

7373
if (result.TryGetValue(key, out T value))
7474
{

src/GraphQL/DataLoader/CollectionBatchDataLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public async Task<IEnumerable<T>> LoadAsync(TKey key)
6060
}
6161
}
6262

63-
var result = await DataLoaded;
63+
var result = await DataLoaded.ConfigureAwait(false);
6464

6565
return result[key];
6666
}

src/GraphQL/Execution/SubscriptionExecutionStrategy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public override async Task<ExecutionResult> ExecuteAsync(ExecutionContext contex
1616
var rootType = GetOperationRootType(context.Document, context.Schema, context.Operation);
1717
var rootNode = BuildExecutionRootNode(context, rootType);
1818

19-
var streams = await ExecuteSubscriptionNodesAsync(context, rootNode.SubFields);
19+
var streams = await ExecuteSubscriptionNodesAsync(context, rootNode.SubFields).ConfigureAwait(false);
2020

2121
ExecutionResult result = new SubscriptionExecutionResult
2222
{
@@ -38,7 +38,7 @@ private async Task<IDictionary<string, IObservable<ExecutionResult>>> ExecuteSub
3838
if (!(node.FieldDefinition is EventStreamFieldType fieldDefinition))
3939
continue;
4040

41-
streams[name] = await ResolveEventStreamAsync(context, node);
41+
streams[name] = await ResolveEventStreamAsync(context, node).ConfigureAwait(false);
4242
}
4343

4444
return streams;
@@ -93,7 +93,7 @@ protected virtual async Task<IObservable<ExecutionResult>> ResolveEventStreamAsy
9393
}
9494
else if (eventStreamField?.AsyncSubscriber != null)
9595
{
96-
subscription = await eventStreamField.AsyncSubscriber.SubscribeAsync(resolveContext);
96+
subscription = await eventStreamField.AsyncSubscriber.SubscribeAsync(resolveContext).ConfigureAwait(false);
9797
}
9898
else
9999
{

src/GraphQL/Http/DocumentWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static async Task<string> WriteToStringAsync<T>(this IDocumentWriter writ
7373
{
7474
using (var stream = new MemoryStream())
7575
{
76-
await writer.WriteAsync(stream, value);
76+
await writer.WriteAsync(stream, value).ConfigureAwait(false);
7777
stream.Position = 0;
7878
using (var reader = new StreamReader(stream, DocumentWriter.Utf8Encoding))
7979
{

src/GraphQL/Http/HttpResponseStreamWriter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public override async Task WriteAsync(char value)
161161

162162
if (_charBufferCount == _charBufferSize)
163163
{
164-
await FlushInternalAsync(flushEncoder: false);
164+
await FlushInternalAsync(flushEncoder: false).ConfigureAwait(false);
165165
}
166166

167167
_charBuffer[_charBufferCount] = value;
@@ -184,7 +184,7 @@ public override async Task WriteAsync(char[] values, int index, int count)
184184
{
185185
if (_charBufferCount == _charBufferSize)
186186
{
187-
await FlushInternalAsync(flushEncoder: false);
187+
await FlushInternalAsync(flushEncoder: false).ConfigureAwait(false);
188188
}
189189

190190
CopyToCharBuffer(values, ref index, ref count);
@@ -209,7 +209,7 @@ public override async Task WriteAsync(string value)
209209
{
210210
if (_charBufferCount == _charBufferSize)
211211
{
212-
await FlushInternalAsync(flushEncoder: false);
212+
await FlushInternalAsync(flushEncoder: false).ConfigureAwait(false);
213213
}
214214

215215
CopyToCharBuffer(value, ref index, ref count);
@@ -304,7 +304,7 @@ private async Task FlushInternalAsync(bool flushEncoder)
304304

305305
if (count > 0)
306306
{
307-
await _stream.WriteAsync(_byteBuffer, 0, count);
307+
await _stream.WriteAsync(_byteBuffer, 0, count).ConfigureAwait(false);
308308
}
309309
}
310310

src/GraphQL/Instrumentation/InstrumentFieldsMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public async Task<object> Resolve(ResolveFieldContext context, FieldMiddlewareDe
1919

2020
using (context.Metrics.Subject("field", context.FieldName, metadata))
2121
{
22-
var result = await next(context);
22+
var result = await next(context).ConfigureAwait(false);
2323
return result;
2424
}
2525
}

src/GraphQL/Introspection/SchemaMetaFieldType.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public __Schema()
2929
"A list of all types supported by this server.",
3030
resolve: async context =>
3131
{
32-
return await context.Schema.AllTypes.WhereAsync(x => context.Schema.Filter.AllowType(x));
32+
return await context.Schema.AllTypes.WhereAsync(x => context.Schema.Filter.AllowType(x)).ConfigureAwait(false);
3333
});
3434

3535
Field<NonNullGraphType<__Type>>(
@@ -45,7 +45,7 @@ public __Schema()
4545
"If this server supports mutation, the type that mutation operations will be rooted at.",
4646
resolve: async context =>
4747
{
48-
if (await context.Schema.Filter.AllowType(context.Schema.Mutation))
48+
if (await context.Schema.Filter.AllowType(context.Schema.Mutation).ConfigureAwait(false))
4949
{
5050
return context.Schema.Mutation;
5151
}
@@ -57,7 +57,7 @@ public __Schema()
5757
"If this server supports subscription, the type that subscription operations will be rooted at.",
5858
resolve: async context =>
5959
{
60-
if (await context.Schema.Filter.AllowType(context.Schema.Subscription))
60+
if (await context.Schema.Filter.AllowType(context.Schema.Subscription).ConfigureAwait(false))
6161
{
6262
return context.Schema.Subscription;
6363
}
@@ -69,7 +69,7 @@ public __Schema()
6969
"A list of all directives supported by this server.",
7070
resolve: async context =>
7171
{
72-
return await context.Schema.Directives.WhereAsync(d => context.Schema.Filter.AllowDirective(d));
72+
return await context.Schema.Directives.WhereAsync(d => context.Schema.Filter.AllowDirective(d)).ConfigureAwait(false);
7373
});
7474
}
7575
}

src/GraphQL/Introspection/__Field.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public __Field()
1919
resolve: async context =>
2020
{
2121
var arguments = context.Source.Arguments ?? Enumerable.Empty<QueryArgument>();
22-
return await arguments.WhereAsync(x => context.Schema.Filter.AllowArgument(context.Source, x));
22+
return await arguments.WhereAsync(x => context.Schema.Filter.AllowArgument(context.Source, x)).ConfigureAwait(false);
2323
});
2424
Field<NonNullGraphType<__Type>>("type", resolve: ctx => ctx.Source.ResolvedType);
2525
Field<NonNullGraphType<BooleanGraphType>>("isDeprecated", resolve: context =>

src/GraphQL/Introspection/__Type.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public __Type()
5050
: type?.Fields;
5151

5252
fields = fields ?? Enumerable.Empty<FieldType>();
53-
fields = await fields.WhereAsync(f => context.Schema.Filter.AllowField(context.Source as IGraphType, f));
53+
fields = await fields.WhereAsync(f => context.Schema.Filter.AllowField(context.Source as IGraphType, f)).ConfigureAwait(false);
5454

5555
return fields.OrderBy(f => f.Name);
5656
}
@@ -60,13 +60,13 @@ public __Type()
6060
{
6161
var type = context.Source as IImplementInterfaces;
6262
if (type == null) return null;
63-
return await type.ResolvedInterfaces.WhereAsync(x => context.Schema.Filter.AllowType(x));
63+
return await type.ResolvedInterfaces.WhereAsync(x => context.Schema.Filter.AllowType(x)).ConfigureAwait(false);
6464
});
6565
FieldAsync<ListGraphType<NonNullGraphType<__Type>>>("possibleTypes", resolve: async context =>
6666
{
6767
if (context.Source is IAbstractGraphType type)
6868
{
69-
return await type.PossibleTypes.WhereAsync(x => context.Schema.Filter.AllowType(x));
69+
return await type.PossibleTypes.WhereAsync(x => context.Schema.Filter.AllowType(x)).ConfigureAwait(false);
7070
}
7171

7272
return null;
@@ -86,7 +86,7 @@ public __Type()
8686
? type.Values.Where(e => string.IsNullOrWhiteSpace(e.DeprecationReason)).ToList()
8787
: type.Values.ToList();
8888

89-
return await values.WhereAsync(v => context.Schema.Filter.AllowEnumValue(type, v));
89+
return await values.WhereAsync(v => context.Schema.Filter.AllowEnumValue(type, v)).ConfigureAwait(false);
9090
}
9191

9292
return null;
@@ -95,7 +95,7 @@ public __Type()
9595
{
9696
var type = context.Source as IInputObjectGraphType;
9797
if (type == null) return null;
98-
return await type.Fields.WhereAsync(f => context.Schema.Filter.AllowField(type, f));
98+
return await type.Fields.WhereAsync(f => context.Schema.Filter.AllowField(type, f)).ConfigureAwait(false);
9999
});
100100
Field<__Type>("ofType", resolve: context =>
101101
{

src/GraphQL/Resolvers/AsyncEventStreamResolver.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public Task<IObservable<T>> SubscribeAsync(ResolveEventStreamContext context)
2323

2424
async Task<IObservable<object>> IAsyncEventStreamResolver.SubscribeAsync(ResolveEventStreamContext context)
2525
{
26-
var result = await SubscribeAsync(context);
26+
var result = await SubscribeAsync(context).ConfigureAwait(false);
2727
return (IObservable<object>)result;
2828
}
2929
}
@@ -45,7 +45,7 @@ public Task<IObservable<TReturnType>> SubscribeAsync(ResolveEventStreamContext c
4545

4646
async Task<IObservable<object>> IAsyncEventStreamResolver.SubscribeAsync(ResolveEventStreamContext context)
4747
{
48-
var result = await SubscribeAsync(context);
48+
var result = await SubscribeAsync(context).ConfigureAwait(false);
4949
return (IObservable<object>)result;
5050
}
5151
}
@@ -73,7 +73,7 @@ async Task<IObservable<object>> IAsyncEventStreamResolver.SubscribeAsync(Resolve
7373
throw new ArgumentException($"Return type of {_accessor.FieldName} should be Task<IObservable<T>>, instead of {_accessor.ReturnType}");
7474
}
7575

76-
await task;
76+
await task.ConfigureAwait(false);
7777

7878
return ((dynamic)task).Result;
7979
}

src/GraphQL/SchemaExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33
using GraphQL.Http;
44
using GraphQL.Types;
@@ -25,7 +25,7 @@ public static async Task<string> ExecuteAsync(this ISchema schema, Action<Execut
2525
{
2626
_.Schema = schema;
2727
configure(_);
28-
});
28+
}).ConfigureAwait(false);
2929
return new DocumentWriter(indent: true).Write(result);
3030
}
3131
}

src/GraphQL/TaskExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal static async Task<IEnumerable<T>> WhereAsync<T>(this IEnumerable<T> ite
5050
}
5151

5252
var itemTaskList = items.Select(item => new { Item = item, PredTask = predicate.Invoke(item) }).ToList();
53-
await Task.WhenAll(itemTaskList.Select(x => x.PredTask));
53+
await Task.WhenAll(itemTaskList.Select(x => x.PredTask)).ConfigureAwait(false);
5454
return itemTaskList.Where(x => x.PredTask.Result).Select(x => x.Item);
5555
}
5656
}

src/GraphQL/Types/ResolveFieldContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public async Task<TResult> TryAsyncResolve<TResult>(Func<ResolveFieldContext<TSo
115115
{
116116
try
117117
{
118-
return await resolve(this);
118+
return await resolve(this).ConfigureAwait(false);
119119
}
120120
catch (Exception ex)
121121
{
@@ -130,7 +130,7 @@ public async Task<TResult> TryAsyncResolve<TResult>(Func<ResolveFieldContext<TSo
130130
else
131131
{
132132
var result = error(Errors);
133-
return result == null ? default : await result;
133+
return result == null ? default : await result.ConfigureAwait(false);
134134
}
135135
}
136136
}

src/GraphQL/Utilities/Federation/FederatedSchemaBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private void AddRootEntityFields(ISchema schema)
9696
Arguments = rep,
9797
ParentFieldContext = context
9898
};
99-
var result = await resolver.Resolve(resolveContext);
99+
var result = await resolver.Resolve(resolveContext).ConfigureAwait(false);
100100
results.Add(result);
101101
}
102102
else

src/GraphQL/Utilities/Federation/FuncFederatedResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public FuncFederatedResolver(Func<FederatedResolveContext, Task<T>> func)
1414

1515
public async Task<object> Resolve(FederatedResolveContext context)
1616
{
17-
return await _resolver(context);
17+
return await _resolver(context).ConfigureAwait(false);
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)