Skip to content

Commit

Permalink
Cleanup warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
byme8 committed Mar 7, 2023
1 parent e0f8efd commit f8cea11
Show file tree
Hide file tree
Showing 33 changed files with 179 additions and 174 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[*.cs]
dotnet_diagnostic.CS1591.severity = none
dotnet_diagnostic.CS8618.severity = none
1 change: 1 addition & 0 deletions ZeroQL.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AFTER_USING_LIST/@EntryValue">1</s:Int64>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QL/@EntryIndexedValue">QL</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
8 changes: 4 additions & 4 deletions src/Benchmarks/ZeroQL.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_ = ZeroQL.TestServer.Program.StartServer(serverContext);
await ZeroQL.TestServer.Program.VerifyServiceIsRunning(serverContext);

var benchmark = new RawVSZeroQL();
var benchmark = new RawVsZeroQL();
var raw = await benchmark.Raw();
var strawberry = await benchmark.StrawberryShake();
var zeroQLLambda = await benchmark.ZeroQLLambda();
Expand All @@ -36,7 +36,7 @@
}

var switcher = new BenchmarkSwitcher(new[] {
typeof(RawVSZeroQL),
typeof(RawVsZeroQL),
typeof(Generation),
});

Expand All @@ -46,7 +46,7 @@
ZeroQL.TestServer.Program.StopServer(serverContext);

[MemoryDiagnoser]
public class RawVSZeroQL
public class RawVsZeroQL
{
private readonly JsonSerializerOptions options = new()
{
Expand All @@ -63,7 +63,7 @@ public class RawVSZeroQL
private readonly StrawberryShakeTestServerClient strawberryShake;
private readonly Upload upload;

public RawVSZeroQL()
public RawVsZeroQL()
{
httpClient = new ImmortalHttpClientForStrawberryShake();
httpClient.BaseAddress = new Uri("http://localhost:10000/graphql");
Expand Down
2 changes: 1 addition & 1 deletion src/TestApp/ZeroQL.TestApp/Generated/GraphQL.g.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// f63f7a964078b30c19f6630749226655
// 291685ad31ee73dba6a2172b2f6dcc25
// This file generated for ZeroQL.
// <auto-generated/>
#pragma warning disable 8618
Expand Down
132 changes: 66 additions & 66 deletions src/TestApp/ZeroQL.TestApp/QueryFragments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,72 +41,72 @@ public static UserModel AsUserWithRoleNameExpression(this User user)

[GraphQLFragment]
public static int SetValues(this Mutation mutation,
string Text,
byte Value1,
byte? Value2,
short Value3,
short? Value4,
int Value5,
int? Value6,
long Value7,
long? Value8,
float Value9,
float? Value10,
double Value11,
double? Value12,
decimal Value13,
decimal? Value14,
DateTime Value15,
DateTime? Value16,
DateOnly Value17,
DateOnly? Value18,
Guid Value19,
Guid? Value20,
Guid[] Value21,
Guid[]? Value22,
Guid[] Value23,
Guid[]? Value24,
Guid[] Value25,
Guid[]? Value26,
KeyValuePairOfStringAndStringInput[] Value27,
KeyValuePairOfStringAndStringInput[]? Value28,
KeyValuePairOfStringAndStringInput Value29,
KeyValuePairOfStringAndStringInput? Value30,
DateTimeOffset Value31,
DateTimeOffset? Value32
string text,
byte value1,
byte? value2,
short value3,
short? value4,
int value5,
int? value6,
long value7,
long? value8,
float value9,
float? value10,
double value11,
double? value12,
decimal value13,
decimal? value14,
DateTime value15,
DateTime? value16,
DateOnly value17,
DateOnly? value18,
Guid value19,
Guid? value20,
Guid[] value21,
Guid[]? value22,
Guid[] value23,
Guid[]? value24,
Guid[] value25,
Guid[]? value26,
KeyValuePairOfStringAndStringInput[] value27,
KeyValuePairOfStringAndStringInput[]? value28,
KeyValuePairOfStringAndStringInput value29,
KeyValuePairOfStringAndStringInput? value30,
DateTimeOffset value31,
DateTimeOffset? value32
)
=> mutation.AddValues(Text,
Value1,
Value2,
Value3,
Value4,
Value5,
Value6,
Value7,
Value8,
Value9,
Value10,
Value11,
Value12,
Value13,
Value14,
Value15,
Value16,
Value17,
Value18,
Value19,
Value20,
Value21,
Value22,
Value23,
Value24,
Value25,
Value26,
Value27,
Value28,
Value29,
Value30,
Value31,
Value32);
=> mutation.AddValues(text,
value1,
value2,
value3,
value4,
value5,
value6,
value7,
value8,
value9,
value10,
value11,
value12,
value13,
value14,
value15,
value16,
value17,
value18,
value19,
value20,
value21,
value22,
value23,
value24,
value25,
value26,
value27,
value28,
value29,
value30,
value31,
value32);

}
3 changes: 2 additions & 1 deletion src/TestApp/ZeroQL.TestApp/QueryFragmentsWithoutNamespace.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using GraphQL.TestServer;
using ZeroQL;
using ZeroQL.TestApp.Models;
using ZeroQL.TestApp;

// ReSharper disable once CheckNamespace
public static partial class QueryFragmentsWithoutNamespace
{
[GraphQLFragment]
Expand Down
6 changes: 3 additions & 3 deletions src/TestApp/ZeroQL.TestApp/User.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ZeroQL.TestApp.Models;
namespace ZeroQL.TestApp;

public record UserModel
{
Expand All @@ -7,7 +7,7 @@ public UserModel()

}

public UserModel(string firstName, string lastName, string role)
public UserModel(string firstName, string lastName, string? role)
{
FirstName = firstName;
LastName = lastName;
Expand All @@ -26,7 +26,7 @@ public string LastName
init;
}

public string Role
public string? Role
{
get;
init;
Expand Down
2 changes: 0 additions & 2 deletions src/ZeroQL.CLI/Commands/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using ZeroQL.Internal;
using ZeroQL.Internal.Enums;

#pragma warning disable CS8618

namespace ZeroQL.CLI.Commands;

[Command("generate", Description = "Generates C# classes from graphql file.")]
Expand Down
6 changes: 3 additions & 3 deletions src/ZeroQL.Runtime/GraphQLClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IGraphQLClient

Task<GraphQLResult<TResult>> Execute<TVariables, TOperationType, TResult>(
TVariables? variables,
Func<TVariables?, TOperationType?, TResult?> queryMapper,
Func<TVariables?, TOperationType, TResult?> queryMapper,
string queryKey,
CancellationToken cancellationToken = default);
}
Expand Down Expand Up @@ -47,7 +47,7 @@ public GraphQLClient(HttpClient httpClient, IGraphQLQueryPipeline? queryPipeline

public async Task<GraphQLResult<TResult>> Execute<TVariables, TOperationType, TResult>(
TVariables? variables,
Func<TVariables?, TOperationType?, TResult?> queryMapper,
Func<TVariables?, TOperationType, TResult?> queryMapper,
string queryKey,
CancellationToken cancellationToken = default)
{
Expand All @@ -62,7 +62,7 @@ public async Task<GraphQLResult<TResult>> Execute<TVariables, TOperationType, TR
return new GraphQLResult<TResult>(result.Query, default, result.Errors, result.Extensions);
}

return new GraphQLResult<TResult>(result.Query, queryMapper(variables, result.Data), result.Errors,
return new GraphQLResult<TResult>(result.Query, queryMapper(variables, result.Data!), result.Errors,
result.Extensions);
}

Expand Down
11 changes: 6 additions & 5 deletions src/ZeroQL.Runtime/GraphQLClientLambdaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
using System.Threading.Tasks;
using ZeroQL;

// ReSharper disable once CheckNamespace
public static class GraphQLClientRequestExtensions
{
public static async Task<GraphQLResult<TResult>> Execute<TQuery, TResult>(
this IGraphQLClient client, GraphQL<TQuery, TResult> request, CancellationToken cancellationToken = default)
{
return await client.Execute<GraphQL<TQuery, TResult>, TQuery, TResult>(
request,
(i, q) => request.Execute(q),
(_, q) => request.Execute(q),
request.GetType().Name,
cancellationToken);
}
Expand Down Expand Up @@ -51,7 +52,7 @@ public static async Task<GraphQLResult<TResult>> Query<TQuery, TMutation, TResul
{
return await client.Execute<Unit, TQuery, TResult>(
null,
(i, q) => query(q),
(_, q) => query(q),
queryKey,
cancellationToken);
}
Expand All @@ -64,7 +65,7 @@ public static async Task<GraphQLResult<TResult>> Query<TQuery, TMutation, TResul
{
return await client.Execute<Unit, TQuery, TResult>(
null,
(i, q) => query(q),
(_, q) => query(q),
queryKey,
cancellationToken);
}
Expand Down Expand Up @@ -99,7 +100,7 @@ public static async Task<GraphQLResult<TResult>> Mutation<TQuery, TMutation, TRe
{
return await client.Execute<Unit, TMutation, TResult>(
null,
(i, q) => query(q),
(_, q) => query(q),
queryKey,
cancellationToken);
}
Expand All @@ -112,7 +113,7 @@ public static async Task<GraphQLResult<TResult>> Mutation<TQuery, TMutation, TRe
{
return await client.Execute<Unit, TMutation, TResult>(
null,
(i, q) => query(q), queryKey,
(_, q) => query(q), queryKey,
cancellationToken);
}
}
2 changes: 1 addition & 1 deletion src/ZeroQL.Runtime/Internal/GraphQLRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GraphQLRequestExtensions
public class GraphQLPersistedQueryExtension
{
[JsonPropertyName("sha256Hash")]
public string? SHA256Hash { get; set; }
public string? Sha256Hash { get; set; }

public int Version { get; set; }
}
2 changes: 1 addition & 1 deletion src/ZeroQL.Runtime/Json/InterfaceJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override void Write(
switch (value)
{
case null:
JsonSerializer.Serialize(writer, default, options);
JsonSerializer.Serialize(writer, default!, options);
break;
default:
{
Expand Down
2 changes: 1 addition & 1 deletion src/ZeroQL.Runtime/Json/ZeroQLUploadJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ZeroQLUploadJsonConverter : JsonConverter<Upload>
public override Upload Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options) => null;
JsonSerializerOptions options) => null!;

public override void Write(
Utf8JsonWriter writer,
Expand Down
2 changes: 1 addition & 1 deletion src/ZeroQL.Runtime/Pipelines/PersistedQueryPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<GraphQLResponse<TQuery>> ExecuteAsync<TQuery>(HttpClient httpC
PersistedQuery = new GraphQLPersistedQueryExtension
{
Version = 1,
SHA256Hash = queryInfo.Hash
Sha256Hash = queryInfo.Hash
}
}
};
Expand Down
1 change: 1 addition & 0 deletions src/ZeroQL.Runtime/Schema/ID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public record ID(string Value)
public static implicit operator string(ID id) => id.Value;
}

// ReSharper disable once InconsistentNaming
public class ZeroQLIDJsonConverter : JsonConverter<ID>
{
public override ID? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Expand Down
12 changes: 6 additions & 6 deletions src/ZeroQL.Runtime/ZeroQLReflectionCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ namespace ZeroQL;

public class ZeroQLReflectionCache
{
private static readonly Dictionary<(Type, string), Func<object, object>> _cache = new();
private static readonly Dictionary<(Type, string), Func<object, object>> Cache = new();

public static object Get(object target, string propertyName)
{
var type = target.GetType();
if (_cache.TryGetValue((type, propertyName), out var func))
if (Cache.TryGetValue((type, propertyName), out var func))
{
return func.Invoke(target);
}

var propertyInfo = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
var propertyInfo = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance)!;
var getter = CreateGetter(propertyInfo);

_cache.Add((type, propertyName), getter);
Cache.Add((type, propertyName), getter);

return getter.Invoke(target);
}

public static Func<object, object> CreateGetter(PropertyInfo property)
{
var objParm = Expression.Parameter(typeof(object), "o");
var lambda = Expression.Lambda(typeof(Func<object, object>), Expression.Property(Expression.Convert(objParm, property.DeclaringType), property.Name), objParm);
var objParam = Expression.Parameter(typeof(object), "o");
var lambda = Expression.Lambda(typeof(Func<object, object>), Expression.Property(Expression.Convert(objParam, property.DeclaringType!), property.Name), objParam);
return (Func<object, object>)lambda.Compile();
}
}
Loading

0 comments on commit f8cea11

Please sign in to comment.