Skip to content

Commit 65924ec

Browse files
authored
NameString argument validation fixes. (#347)
1 parent 32fed94 commit 65924ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+273
-441
lines changed

src/Abstractions/GraphQLNonNullAttribute.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ namespace HotChocolate
77
public sealed class GraphQLNonNullAttribute
88
: Attribute
99
{
10-
public bool ElementIsNullable { get; set; } = false;
11-
public bool IsNullable { get; set; } = false;
10+
public bool ElementIsNullable { get; set; }
11+
12+
public bool IsNullable { get; set; }
1213
}
1314
}

src/Core/Execution/ExecutionContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private static object ResolveRootValue(
172172
object initialValue)
173173
{
174174
object initVal = initialValue;
175-
if (initVal == null && schema.TryGetNativeType(
175+
if (initVal == null && schema.TryGetClrType(
176176
operationType.Name, out Type nativeType))
177177
{
178178
initVal = services.GetService(nativeType);
@@ -185,7 +185,7 @@ private static object CreateRootValue(
185185
ISchema schema,
186186
ObjectType operationType)
187187
{
188-
if (schema.TryGetNativeType(
188+
if (schema.TryGetClrType(
189189
operationType.Name,
190190
out Type nativeType))
191191
{

src/Core/Execution/ExecutionStrategyBase.Resolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ Task<object> ExecuteResolver()
105105
return ExecuteFieldMiddlewareAsync(
106106
resolverTask,
107107
cancellationToken);
108-
};
108+
}
109109
}
110110

111-
protected void CompleteValue(
111+
protected static void CompleteValue(
112112
FieldValueCompletionContext completionContext)
113113
{
114114
_fieldValueCompleter.CompleteValue(completionContext);

src/Core/Execution/ExecutionStrategyBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ private async Task ExecuteResolverBatchAsync(
6464
{
6565
// start field resolvers
6666
BeginExecuteResolverBatch(
67-
executionContext,
6867
currentBatch,
6968
cancellationToken);
7069

@@ -82,7 +81,6 @@ await EndExecuteResolverBatchAsync(
8281
}
8382

8483
private void BeginExecuteResolverBatch(
85-
IExecutionContext executionContext,
8684
IEnumerable<ResolverTask> currentBatch,
8785
CancellationToken cancellationToken)
8886
{

src/Core/Execution/SubscriptionExecutionStrategy.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace HotChocolate.Execution
1313
internal class SubscriptionExecutionStrategy
1414
: ExecutionStrategyBase
1515
{
16-
public override async Task<IExecutionResult> ExecuteAsync(
16+
public override Task<IExecutionResult> ExecuteAsync(
1717
IExecutionContext executionContext,
1818
CancellationToken cancellationToken)
1919
{
@@ -22,10 +22,17 @@ public override async Task<IExecutionResult> ExecuteAsync(
2222
throw new ArgumentNullException(nameof(executionContext));
2323
}
2424

25-
EventDescription @event = CreateEvent(executionContext);
25+
return ExecuteInternalAsync(executionContext, cancellationToken);
26+
}
27+
28+
private async Task<IExecutionResult> ExecuteInternalAsync(
29+
IExecutionContext executionContext,
30+
CancellationToken cancellationToken)
31+
{
32+
EventDescription eventDescription = CreateEvent(executionContext);
2633

2734
IEventStream eventStream = await SubscribeAsync(
28-
executionContext.Services, @event);
35+
executionContext.Services, eventDescription);
2936

3037
return new SubscriptionResult(
3138
eventStream,
@@ -36,7 +43,8 @@ public override async Task<IExecutionResult> ExecuteAsync(
3643
ExecuteSubscriptionQueryAsync);
3744
}
3845

39-
private EventDescription CreateEvent(IExecutionContext executionContext)
46+
private EventDescription CreateEvent(
47+
IExecutionContext executionContext)
4048
{
4149
IReadOnlyCollection<FieldSelection> selections = executionContext
4250
.CollectFields(

src/Core/Execution/Utilities/ArgumentResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Dictionary<string, ArgumentValue> CoerceArgumentValues(
4343
return coercedArgumentValues;
4444
}
4545

46-
private object CoerceArgumentValue(
46+
private static object CoerceArgumentValue(
4747
string argumentName,
4848
IInputType argumentType,
4949
IValueNode defaultValue,

src/Core/Execution/Utilities/DictionaryToObjectConverter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ protected override void VisitList(
6767
}
6868
else
6969
{
70-
Type elementType = DotNetTypeInfoFactory.GetInnerListType(context.Type);
70+
Type elementType = DotNetTypeInfoFactory
71+
.GetInnerListType(context.Type);
72+
7173
if (elementType != null)
7274
{
7375
Type listType = typeof(List<>).MakeGenericType(elementType);
@@ -79,8 +81,10 @@ protected override void VisitList(
7981
valueContext.Type = context.Type.GetElementType();
8082
Visit(list[i], valueContext);
8183

82-
list.Add(valueContext.Object);
84+
l.Add(valueContext.Object);
8385
}
86+
87+
context.Object = l;
8488
}
8589
}
8690
}

src/Core/Execution/Utilities/DirectiveCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private IEnumerable<IDirective> GetFieldSelectionDirectives(
123123
}
124124
}
125125

126-
private void CollectTypeSystemDirectives(
126+
private static void CollectTypeSystemDirectives(
127127
HashSet<string> processed,
128128
List<IDirective> directives,
129129
ObjectField field)

src/Core/Execution/Utilities/FieldCollector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private void ResolveFields(
8282
}
8383
}
8484

85-
private void ResolveFieldSelection(
85+
private static void ResolveFieldSelection(
8686
ObjectType type,
8787
FieldNode fieldSelection,
8888
Action<QueryError> reportError,
@@ -142,7 +142,7 @@ private bool ShouldBeIncluded(ISelectionNode selection)
142142
return selection.Directives.Include(_variables);
143143
}
144144

145-
private bool DoesTypeApply(IType typeCondition, ObjectType current)
145+
private static bool DoesTypeApply(IType typeCondition, ObjectType current)
146146
{
147147
if (typeCondition is ObjectType ot)
148148
{

src/Core/Execution/Utilities/QueryResultVisitor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
namespace HotChocolate.Execution
99
{
10-
internal abstract class QueryResultVisitor<TContext>
10+
internal class QueryResultVisitor<TContext>
1111
{
12+
protected QueryResultVisitor()
13+
{
14+
}
15+
1216
public virtual void Visit(object value, TContext context)
1317
{
1418
if (value is IDictionary<string, object> dictionary)
@@ -52,7 +56,6 @@ protected virtual void VisitList(IList<object> list, TContext context)
5256

5357
protected virtual void VisitValue(object value, TContext context)
5458
{
55-
5659
}
5760
}
5861
}

0 commit comments

Comments
 (0)