Skip to content

Commit

Permalink
Fixed code warnings. (#2599)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Nov 18, 2020
1 parent bec4398 commit 30974bb
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 187 deletions.
Expand Up @@ -6,7 +6,7 @@ namespace HotChocolate.Execution.Caching
{
internal sealed class DefaultDocumentCache : IDocumentCache
{
private Cache<DocumentNode> _cache;
private readonly Cache<DocumentNode> _cache;

public DefaultDocumentCache(int capacity = 100)
{
Expand Down
Expand Up @@ -19,7 +19,7 @@ public interface ISchemaOptions
/// Defines if fields shall be sorted by name.
/// Default: <c>false</c>
/// </summary>
bool SortFieldsByName { get; set; }
new bool SortFieldsByName { get; set; }

/// <summary>
/// Defines if types shall be removed from the schema that are
Expand Down
Expand Up @@ -26,7 +26,7 @@ internal static class ComplexOutputTypeValidationHelper
IComplexOutputType type,
ICollection<ISchemaError> errors)
{
for (int i = 0; i < type.Fields.Count; i++)
for (var i = 0; i < type.Fields.Count; i++)
{
IOutputField field = type.Fields[i];

Expand All @@ -37,7 +37,7 @@ internal static class ComplexOutputTypeValidationHelper
errors.Add(TwoUnderscoresNotAllowedField(type, field));
}

for (int j = 0; j < field.Arguments.Count; j++)
for (var j = 0; j < field.Arguments.Count; j++)
{
IInputField argument = field.Arguments[j];

Expand Down Expand Up @@ -77,7 +77,7 @@ internal static class ComplexOutputTypeValidationHelper

foreach (IOutputField implementedField in implementedType.Fields)
{
if (type.Fields.TryGetField(implementedField.Name, out IOutputField field))
if (type.Fields.TryGetField(implementedField.Name, out IOutputField? field))
{
ValidateArguments(field, implementedField, errors);

Expand All @@ -100,10 +100,9 @@ internal static class ComplexOutputTypeValidationHelper
{
var implArgs = implementedField.Arguments.ToDictionary(t => t.Name);

foreach (Argument argument in field.Arguments)
foreach (var argument in field.Arguments)
{
if (implArgs.TryGetValue(
argument.Name, out IInputField? implementedArgument))
if (implArgs.TryGetValue(argument.Name, out IInputField? implementedArgument))
{
implArgs.Remove(argument.Name);
if (!argument.Type.IsEqualTo(implementedArgument.Type))
Expand All @@ -121,7 +120,7 @@ internal static class ComplexOutputTypeValidationHelper
}
}

foreach (Argument missingArgument in implArgs.Values)
foreach (var missingArgument in implArgs.Values)
{
errors.Add(ArgumentNotImplemented(
field, implementedField, missingArgument));
Expand All @@ -132,7 +131,7 @@ internal static class ComplexOutputTypeValidationHelper
IComplexOutputType type,
IInterfaceType implementedType)
{
foreach (InterfaceType interfaceType in implementedType.Interfaces)
foreach (var interfaceType in implementedType.Interfaces)
{
if (!type.IsImplementing(interfaceType))
{
Expand Down
Expand Up @@ -26,7 +26,7 @@ public static class DataLoaderObjectFieldExtensions
this IObjectFieldDescriptor descriptor,
Type dataLoaderType)
{
FieldMiddleware placeholder = next => context => default;
FieldMiddleware placeholder = _ => _ => default;

if (!TryGetDataLoaderTypes(dataLoaderType, out Type? keyType, out Type? valueType))
{
Expand All @@ -43,17 +43,11 @@ public static class DataLoaderObjectFieldExtensions
if (!valueType.IsArray)
{
IExtendedType resolverType =
c.TypeInspector.GetType(definition.ResultType);
if (resolverType.IsArrayOrList)
{
schemaType = c.TypeInspector.GetType(
typeof(IEnumerable<>).MakeGenericType(valueType));
}
else
{
schemaType = c.TypeInspector.GetType(valueType);
}
c.TypeInspector.GetType(definition.ResultType!);
schemaType = c.TypeInspector.GetType(resolverType.IsArrayOrList
? typeof(IEnumerable<>).MakeGenericType(valueType)
: valueType);
}
else
{
Expand All @@ -66,7 +60,7 @@ public static class DataLoaderObjectFieldExtensions
.New<ObjectFieldDefinition>()
.Definition(definition)
.Configure(
(context, def) =>
(_, def) =>
{
CompileMiddleware(
def,
Expand Down Expand Up @@ -94,7 +88,7 @@ public static class DataLoaderObjectFieldExtensions
{
middlewareType =
typeof(GroupedDataLoaderMiddleware<,,>)
.MakeGenericType(dataLoaderType, keyType, valueType.GetElementType());
.MakeGenericType(dataLoaderType, keyType, valueType.GetElementType()!);
}
else
{
Expand Down Expand Up @@ -145,7 +139,7 @@ public GroupedDataLoaderMiddleware(FieldDelegate next)

public async Task InvokeAsync(IMiddlewareContext context)
{
var dataloader = context.DataLoader<TDataLoader>();
TDataLoader dataloader = context.DataLoader<TDataLoader>();

await _next(context).ConfigureAwait(false);

Expand All @@ -159,7 +153,7 @@ public async Task InvokeAsync(IMiddlewareContext context)
{
for (var n = 0; n < data[m].Length; n++)
{
result.Add(data[m][n]);
result.Add(data[m][n]!);
}
}

Expand All @@ -185,7 +179,7 @@ public DataLoaderMiddleware(FieldDelegate next)

public async Task InvokeAsync(IMiddlewareContext context)
{
var dataloader = context.DataLoader<TDataLoader>();
TDataLoader dataloader = context.DataLoader<TDataLoader>();

await _next(context).ConfigureAwait(false);

Expand Down
Expand Up @@ -10,11 +10,8 @@ namespace HotChocolate.Types.Descriptors
{
public sealed class DescriptorContext : IDescriptorContext
{
private readonly Dictionary<(Type, string?), IConvention> _conventions =
new Dictionary<(Type, string?), IConvention>();

private readonly IReadOnlyDictionary<(Type, string?), List<CreateConvention>>
_convFactories;
private readonly Dictionary<(Type, string?), IConvention> _conventions = new();
private readonly IReadOnlyDictionary<(Type, string?), List<CreateConvention>> _cFactories;

private readonly IServiceProvider _services;

Expand All @@ -25,15 +22,15 @@ public sealed class DescriptorContext : IDescriptorContext

private DescriptorContext(
IReadOnlySchemaOptions options,
IReadOnlyDictionary<(Type, string?), List<CreateConvention>> convFactories,
IReadOnlyDictionary<(Type, string?), List<CreateConvention>> conventionFactories,
IServiceProvider services,
IDictionary<string, object?> contextData,
SchemaBuilder.LazySchema schema,
ISchemaInterceptor schemaInterceptor,
ITypeInterceptor typeInterceptor)
{
Options = options;
_convFactories = convFactories;
_cFactories = conventionFactories;
_services = services;
ContextData = contextData;
SchemaInterceptor = schemaInterceptor;
Expand Down Expand Up @@ -137,7 +134,7 @@ public ITypeInspector TypeInspector
createdConvention = null;
extensions = new List<IConventionExtension>();

if (_convFactories.TryGetValue(
if (_cFactories.TryGetValue(
(typeof(T), scope),
out List<CreateConvention>? factories))
{
Expand Down Expand Up @@ -190,7 +187,7 @@ public ITypeInspector TypeInspector
ISchemaInterceptor? schemaInterceptor = null,
ITypeInterceptor? typeInterceptor = null)
{
return new DescriptorContext(
return new(
options ?? new SchemaOptions(),
conventions ?? new Dictionary<(Type, string?), List<CreateConvention>>(),
services ?? new EmptyServiceProvider(),
Expand Down
Expand Up @@ -291,7 +291,7 @@ public new IObjectFieldDescriptor Ignore(bool ignore = true)
}

public IObjectFieldDescriptor ResolveWith<TResolver>(
Expression<Func<TResolver, object>> propertyOrMethod)
Expression<Func<TResolver, object?>> propertyOrMethod)
{
if (propertyOrMethod is null)
{
Expand Down
Expand Up @@ -4,7 +4,6 @@
using System.Linq.Expressions;
using System.Reflection;
using HotChocolate.Language;
using HotChocolate.Properties;
using HotChocolate.Types.Descriptors.Definitions;
using HotChocolate.Utilities;
using static HotChocolate.Properties.TypeResources;
Expand Down Expand Up @@ -176,7 +175,7 @@ public IObjectTypeDescriptor Interface<TInterface>()
if (typeof(TInterface) == typeof(InterfaceType))
{
throw new ArgumentException(
TypeResources.ObjectTypeDescriptor_InterfaceBaseClass);
ObjectTypeDescriptor_InterfaceBaseClass);
}

Definition.Interfaces.Add(
Expand Down Expand Up @@ -269,7 +268,7 @@ public IObjectFieldDescriptor Field(NameString name)
{
ObjectFieldDescriptor fieldDescriptor =
Fields.FirstOrDefault(t => t.Definition.Member == propertyOrMethod);
if (fieldDescriptor is { })
if (fieldDescriptor is not null)
{
return fieldDescriptor;
}
Expand Down
@@ -1,3 +1,5 @@
#nullable enable

namespace HotChocolate.Types
{
/// <summary>
Expand Down
Expand Up @@ -204,7 +204,7 @@ public IdValue Deserialize(string serializedId)

Span<byte> decoded = serialized.Slice(0, bytesWritten);

NameString schemaName;
NameString schemaName = null;

if (decoded[0] == _schema)
{
Expand Down
12 changes: 6 additions & 6 deletions src/HotChocolate/Core/src/Types/Types/Scalars/UrlType.cs
@@ -1,13 +1,13 @@
using System;
using System.Diagnostics.CodeAnalysis;
using HotChocolate.Language;
using HotChocolate.Properties;

#nullable enable

namespace HotChocolate.Types
{
public sealed class UrlType
: ScalarType<Uri, StringValueNode>
public sealed class UrlType : ScalarType<Uri, StringValueNode>
{
/// <summary>
/// Initializes a new instance of the <see cref="UrlType"/> class.
Expand Down Expand Up @@ -41,7 +41,7 @@ protected override bool IsInstanceOfType(StringValueNode valueSyntax)

protected override Uri ParseLiteral(StringValueNode valueSyntax)
{
if (TryParseUri(valueSyntax.Value, out Uri uri))
if (TryParseUri(valueSyntax.Value, out Uri? uri))
{
return uri;
}
Expand All @@ -53,7 +53,7 @@ protected override Uri ParseLiteral(StringValueNode valueSyntax)

protected override StringValueNode ParseValue(Uri runtimeValue)
{
return new StringValueNode(runtimeValue.AbsoluteUri);
return new(runtimeValue.AbsoluteUri);
}

public override IValueNode ParseResult(object? resultValue)
Expand Down Expand Up @@ -104,7 +104,7 @@ public override bool TryDeserialize(object? resultValue, out object? runtimeValu
return true;
}

if (resultValue is string s && TryParseUri(s, out Uri uri))
if (resultValue is string s && TryParseUri(s, out Uri? uri))
{
runtimeValue = uri;
return true;
Expand All @@ -120,7 +120,7 @@ public override bool TryDeserialize(object? resultValue, out object? runtimeValu
return false;
}

private bool TryParseUri(string value, out Uri uri) =>
private bool TryParseUri(string value, [NotNullWhen(true)] out Uri? uri) =>
Uri.TryCreate(value, UriKind.Absolute, out uri);
}
}
Expand Up @@ -82,7 +82,7 @@ public static Expression Not(Expression expression)
return Expression.Call(
typeof(Enumerable),
nameof(Enumerable.Contains),
new Type[] { genericType },
new[] { genericType },
Expression.Constant(parsedValue),
property);
}
Expand Down
Expand Up @@ -51,7 +51,7 @@ public sealed class ComparableInOperationHandler

object ParseValue()
{
var parsedValue = type.ParseLiteral(value);
object? parsedValue = type.ParseLiteral(value);
Type elementType = type.ElementType().ToRuntimeType();

if (operation.Property.PropertyType != elementType)
Expand Down
Expand Up @@ -38,7 +38,7 @@ public abstract class ComparableOperationHandlerBase
object ParseValue()
{

var parsedValue = type.ParseLiteral(value);
object? parsedValue = type.ParseLiteral(value);

if (!operation.Property.PropertyType.IsInstanceOfType(parsedValue))
{
Expand Down
Expand Up @@ -17,7 +17,7 @@ public abstract class StringOperationHandlerBase
if (operation.Type == typeof(string) &&
type.IsInstanceOfType(value))
{
object parsedValue = type.ParseLiteral(value);
object? parsedValue = type.ParseLiteral(value);

Expression property = context.GetInstance();

Expand Down

0 comments on commit 30974bb

Please sign in to comment.