Skip to content

Commit 755bd98

Browse files
committed
fix remaining conde style issues
1 parent 19b5ae5 commit 755bd98

File tree

50 files changed

+567
-691
lines changed

Some content is hidden

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

50 files changed

+567
-691
lines changed

examples/GraphQL.Client.Example/PersonAndFilmsResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
22

3-
namespace GraphQL.Client.Http.Examples
3+
namespace GraphQL.Client.Example
44
{
55
public class PersonAndFilmsResponse
66
{

examples/GraphQL.Client.Example/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
using System.Linq;
33
using System.Text.Json;
44
using System.Threading.Tasks;
5-
using GraphQL.Client.Serializer.Newtonsoft;
5+
using GraphQL.Client.Http;
66

7-
namespace GraphQL.Client.Http.Examples
7+
namespace GraphQL.Client.Example
88
{
99

1010
public class Program
1111
{
1212

1313
public static async Task Main(string[] args)
1414
{
15-
15+
_ = args;
1616
using var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/");
1717

1818
var personAndFilmsRequest = new GraphQLRequest

src/GraphQL.Client.Abstractions.Websocket/GraphQLWebSocketRequest.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Runtime.Serialization;
43
using System.Threading.Tasks;
54

65
namespace GraphQL.Client.Abstractions.Websocket
@@ -11,38 +10,38 @@ namespace GraphQL.Client.Abstractions.Websocket
1110
/// </summary>
1211
public class GraphQLWebSocketRequest : Dictionary<string, object>, IEquatable<GraphQLWebSocketRequest>
1312
{
14-
public const string IdKey = "id";
15-
public const string TypeKey = "type";
16-
public const string PayloadKey = "payload";
13+
public const string ID_KEY = "id";
14+
public const string TYPE_KEY = "type";
15+
public const string PAYLOAD_KEY = "payload";
1716

1817
/// <summary>
1918
/// The Identifier of the Response
2019
/// </summary>
2120
public string Id
2221
{
23-
get => ContainsKey(IdKey) ? (string)this[IdKey] : null;
24-
set => this[IdKey] = value;
22+
get => ContainsKey(ID_KEY) ? (string)this[ID_KEY] : null;
23+
set => this[ID_KEY] = value;
2524
}
2625

2726
/// <summary>
2827
/// The Type of the Request
2928
/// </summary>
3029
public string Type
3130
{
32-
get => ContainsKey(TypeKey) ? (string)this[TypeKey] : null;
33-
set => this[TypeKey] = value;
31+
get => ContainsKey(TYPE_KEY) ? (string)this[TYPE_KEY] : null;
32+
set => this[TYPE_KEY] = value;
3433
}
3534

3635
/// <summary>
3736
/// The payload of the websocket request
3837
/// </summary>
3938
public GraphQLRequest Payload
4039
{
41-
get => ContainsKey(PayloadKey) ? (GraphQLRequest)this[PayloadKey] : null;
42-
set => this[PayloadKey] = value;
40+
get => ContainsKey(PAYLOAD_KEY) ? (GraphQLRequest)this[PAYLOAD_KEY] : null;
41+
set => this[PAYLOAD_KEY] = value;
4342
}
4443

45-
private TaskCompletionSource<bool> _tcs = new TaskCompletionSource<bool>();
44+
private readonly TaskCompletionSource<bool> _tcs = new TaskCompletionSource<bool>();
4645

4746
/// <summary>
4847
/// Task used to await the actual send operation and to convey potential exceptions
@@ -67,7 +66,7 @@ public GraphQLRequest Payload
6766
public void SendCanceled() => _tcs.SetCanceled();
6867

6968
/// <inheritdoc />
70-
public override bool Equals(object obj) => this.Equals(obj as GraphQLWebSocketRequest);
69+
public override bool Equals(object obj) => Equals(obj as GraphQLWebSocketRequest);
7170

7271
/// <inheritdoc />
7372
public bool Equals(GraphQLWebSocketRequest other)
@@ -80,15 +79,15 @@ public bool Equals(GraphQLWebSocketRequest other)
8079
{
8180
return true;
8281
}
83-
if (!Equals(this.Id, other.Id))
82+
if (!Equals(Id, other.Id))
8483
{
8584
return false;
8685
}
87-
if (!Equals(this.Type, other.Type))
86+
if (!Equals(Type, other.Type))
8887
{
8988
return false;
9089
}
91-
if (!Equals(this.Payload, other.Payload))
90+
if (!Equals(Payload, other.Payload))
9291
{
9392
return false;
9493
}
@@ -99,9 +98,9 @@ public bool Equals(GraphQLWebSocketRequest other)
9998
public override int GetHashCode()
10099
{
101100
var hashCode = 9958074;
102-
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.Id);
103-
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.Type);
104-
hashCode = hashCode * -1521134295 + EqualityComparer<object>.Default.GetHashCode(this.Payload);
101+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Id);
102+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Type);
103+
hashCode = hashCode * -1521134295 + EqualityComparer<object>.Default.GetHashCode(Payload);
105104
return hashCode;
106105
}
107106

src/GraphQL.Client.Abstractions.Websocket/GraphQLWebSocketResponse.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class GraphQLWebSocketResponse : IEquatable<GraphQLWebSocketResponse>
2121
public string Type { get; set; }
2222

2323
/// <inheritdoc />
24-
public override bool Equals(object obj) => this.Equals(obj as GraphQLWebSocketResponse);
24+
public override bool Equals(object obj) => Equals(obj as GraphQLWebSocketResponse);
2525

2626
/// <inheritdoc />
2727
public bool Equals(GraphQLWebSocketResponse other)
@@ -36,12 +36,12 @@ public bool Equals(GraphQLWebSocketResponse other)
3636
return true;
3737
}
3838

39-
if (!Equals(this.Id, other.Id))
39+
if (!Equals(Id, other.Id))
4040
{
4141
return false;
4242
}
4343

44-
if (!Equals(this.Type, other.Type))
44+
if (!Equals(Type, other.Type))
4545
{
4646
return false;
4747
}
@@ -53,8 +53,8 @@ public bool Equals(GraphQLWebSocketResponse other)
5353
public override int GetHashCode()
5454
{
5555
var hashCode = 9958074;
56-
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.Id);
57-
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.Type);
56+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Id);
57+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Type);
5858
return hashCode;
5959
}
6060

@@ -74,7 +74,7 @@ public class GraphQLWebSocketResponse<TPayload> : GraphQLWebSocketResponse, IEqu
7474

7575
public bool Equals(GraphQLWebSocketResponse<TPayload>? other)
7676
{
77-
if (ReferenceEquals(null, other))
77+
if (other is null)
7878
return false;
7979
if (ReferenceEquals(this, other))
8080
return true;
@@ -83,11 +83,11 @@ public bool Equals(GraphQLWebSocketResponse<TPayload>? other)
8383

8484
public override bool Equals(object? obj)
8585
{
86-
if (ReferenceEquals(null, obj))
86+
if (obj is null)
8787
return false;
8888
if (ReferenceEquals(this, obj))
8989
return true;
90-
if (obj.GetType() != this.GetType())
90+
if (obj.GetType() != GetType())
9191
return false;
9292
return Equals((GraphQLWebSocketResponse<TPayload>)obj);
9393
}

src/GraphQL.Client.Abstractions/GraphQLClientExtensions.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,46 @@ public static Task<GraphQLResponse<TResponse>> SendQueryAsync<TResponse>(this IG
1010
string query, object? variables = null,
1111
string? operationName = null, Func<TResponse> defineResponseType = null, CancellationToken cancellationToken = default)
1212
{
13-
return client.SendQueryAsync<TResponse>(new GraphQLRequest(query, variables, operationName), cancellationToken: cancellationToken);
13+
_ = defineResponseType;
14+
return client.SendQueryAsync<TResponse>(new GraphQLRequest(query, variables, operationName),
15+
cancellationToken: cancellationToken);
1416
}
17+
1518
public static Task<GraphQLResponse<TResponse>> SendMutationAsync<TResponse>(this IGraphQLClient client,
1619
string query, object? variables = null,
1720
string? operationName = null, Func<TResponse> defineResponseType = null, CancellationToken cancellationToken = default)
1821
{
19-
return client.SendMutationAsync<TResponse>(new GraphQLRequest(query, variables, operationName), cancellationToken: cancellationToken);
22+
_ = defineResponseType;
23+
return client.SendMutationAsync<TResponse>(new GraphQLRequest(query, variables, operationName),
24+
cancellationToken: cancellationToken);
2025
}
2126

2227
public static Task<GraphQLResponse<TResponse>> SendQueryAsync<TResponse>(this IGraphQLClient client,
2328
GraphQLRequest request, Func<TResponse> defineResponseType, CancellationToken cancellationToken = default)
24-
=> client.SendQueryAsync<TResponse>(request, cancellationToken);
29+
{
30+
_ = defineResponseType;
31+
return client.SendQueryAsync<TResponse>(request, cancellationToken);
32+
}
2533

2634
public static Task<GraphQLResponse<TResponse>> SendMutationAsync<TResponse>(this IGraphQLClient client,
2735
GraphQLRequest request, Func<TResponse> defineResponseType, CancellationToken cancellationToken = default)
28-
=> client.SendMutationAsync<TResponse>(request, cancellationToken);
36+
{
37+
_ = defineResponseType;
38+
return client.SendMutationAsync<TResponse>(request, cancellationToken);
39+
}
2940

3041
public static IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TResponse>(
3142
this IGraphQLClient client, GraphQLRequest request, Func<TResponse> defineResponseType)
32-
=> client.CreateSubscriptionStream<TResponse>(request);
43+
{
44+
_ = defineResponseType;
45+
return client.CreateSubscriptionStream<TResponse>(request);
46+
}
3347

3448
public static IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TResponse>(
3549
this IGraphQLClient client, GraphQLRequest request, Func<TResponse> defineResponseType, Action<Exception> exceptionHandler)
36-
=> client.CreateSubscriptionStream<TResponse>(request, exceptionHandler);
50+
{
51+
_ = defineResponseType;
52+
return client.CreateSubscriptionStream<TResponse>(request, exceptionHandler);
53+
}
3754
}
3855
}

src/GraphQL.Client.Abstractions/GraphQLJsonSerializerExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics;
32
using System.Linq;
43

54
namespace GraphQL.Client.Abstractions

src/GraphQL.Client.LocalExecution/GraphQLLocalExecutionClient.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static GraphQLLocalExecutionClient<TSchema> New<TSchema>(TSchema schema,
2929
public class GraphQLLocalExecutionClient<TSchema> : IGraphQLClient where TSchema : ISchema
3030
{
3131

32-
private static readonly JsonSerializerSettings VariablesSerializerSettings = new JsonSerializerSettings
32+
private static readonly JsonSerializerSettings _variablesSerializerSettings = new JsonSerializerSettings
3333
{
3434
Formatting = Formatting.Indented,
3535
DateTimeZoneHandling = DateTimeZoneHandling.Local,
@@ -44,15 +44,15 @@ public class GraphQLLocalExecutionClient<TSchema> : IGraphQLClient where TSchema
4444
public IGraphQLJsonSerializer Serializer { get; }
4545

4646

47-
private readonly DocumentExecuter documentExecuter;
47+
private readonly DocumentExecuter _documentExecuter;
4848

4949
public GraphQLLocalExecutionClient(TSchema schema)
5050
{
5151
Serializer.EnsureAssigned();
5252
Schema = schema;
5353
if (!Schema.Initialized)
5454
Schema.Initialize();
55-
documentExecuter = new DocumentExecuter();
55+
_documentExecuter = new DocumentExecuter();
5656
}
5757

5858
public GraphQLLocalExecutionClient(TSchema schema, IGraphQLJsonSerializer serializer) : this(schema)
@@ -68,13 +68,11 @@ public Task<GraphQLResponse<TResponse>> SendQueryAsync<TResponse>(GraphQLRequest
6868
public Task<GraphQLResponse<TResponse>> SendMutationAsync<TResponse>(GraphQLRequest request, CancellationToken cancellationToken = default)
6969
=> ExecuteQueryAsync<TResponse>(request, cancellationToken);
7070

71-
public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TResponse>(GraphQLRequest request)
72-
{
73-
return Observable.Defer(() => ExecuteSubscriptionAsync<TResponse>(request).ToObservable())
71+
public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TResponse>(GraphQLRequest request) =>
72+
Observable.Defer(() => ExecuteSubscriptionAsync<TResponse>(request).ToObservable())
7473
.Concat()
7574
.Publish()
7675
.RefCount();
77-
}
7876

7977
public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TResponse>(GraphQLRequest request,
8078
Action<Exception> exceptionHandler)
@@ -100,11 +98,11 @@ private async Task<ExecutionResult> ExecuteAsync(GraphQLRequest request, Cancell
10098

10199
var deserializedRequest = JsonConvert.DeserializeObject<GraphQLRequest>(serializedRequest);
102100
var inputs = deserializedRequest.Variables != null
103-
? (JObject.FromObject(request.Variables, JsonSerializer.Create(VariablesSerializerSettings)) as JObject)
101+
? (JObject.FromObject(request.Variables, JsonSerializer.Create(_variablesSerializerSettings)) as JObject)
104102
.ToInputs()
105103
: null;
106104

107-
var result = await documentExecuter.ExecuteAsync(options =>
105+
var result = await _documentExecuter.ExecuteAsync(options =>
108106
{
109107
options.Schema = Schema;
110108
options.OperationName = request.OperationName;
@@ -119,7 +117,7 @@ private async Task<ExecutionResult> ExecuteAsync(GraphQLRequest request, Cancell
119117
private Task<GraphQLResponse<TResponse>> ExecutionResultToGraphQLResponse<TResponse>(ExecutionResult executionResult, CancellationToken cancellationToken = default)
120118
{
121119
// serialize result into utf8 byte stream
122-
var resultStream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(executionResult, VariablesSerializerSettings)));
120+
var resultStream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(executionResult, _variablesSerializerSettings)));
123121
// deserialize using the provided serializer
124122
return Serializer.DeserializeFromUtf8StreamAsync<TResponse>(resultStream, cancellationToken);
125123
}

src/GraphQL.Client.Serializer.Newtonsoft/GraphQLExtensionsConverter.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Text;
63
using Newtonsoft.Json;
74
using Newtonsoft.Json.Linq;
85

96
namespace GraphQL.Client.Serializer.Newtonsoft
107
{
118
public class GraphQLExtensionsConverter : JsonConverter<GraphQLExtensionsType>
129
{
13-
public override void WriteJson(JsonWriter writer, GraphQLExtensionsType value, JsonSerializer serializer)
14-
{
10+
public override void WriteJson(JsonWriter writer, GraphQLExtensionsType value, JsonSerializer serializer) =>
1511
throw new NotImplementedException(
1612
"This converter currently is only intended to be used to read a JSON object into a strongly-typed representation.");
17-
}
1813

1914
public override GraphQLExtensionsType ReadJson(JsonReader reader, Type objectType, GraphQLExtensionsType existingValue,
2015
bool hasExistingValue, JsonSerializer serializer)
@@ -28,9 +23,8 @@ public override GraphQLExtensionsType ReadJson(JsonReader reader, Type objectTyp
2823
throw new ArgumentException("This converter can only parse when the root element is a JSON Object.");
2924
}
3025

31-
private object ReadToken(JToken? token)
32-
{
33-
return token.Type switch
26+
private object ReadToken(JToken? token) =>
27+
token.Type switch
3428
{
3529
JTokenType.Undefined => null,
3630
JTokenType.None => null,
@@ -52,7 +46,6 @@ private object ReadToken(JToken? token)
5246
JTokenType.Comment => throw new ArgumentOutOfRangeException(nameof(token.Type), "cannot deserialize a JSON comment"),
5347
_ => throw new ArgumentOutOfRangeException(nameof(token.Type))
5448
};
55-
}
5649

5750
private TDictionary ReadDictionary<TDictionary>(JToken element) where TDictionary : Dictionary<string, object>
5851
{
@@ -76,9 +69,6 @@ private IEnumerable<object> ReadArray(JToken element)
7669
}
7770
}
7871

79-
private bool IsUnsupportedJTokenType(JTokenType type)
80-
{
81-
return type == JTokenType.Constructor || type == JTokenType.Property || type == JTokenType.Comment;
82-
}
72+
private bool IsUnsupportedJTokenType(JTokenType type) => type == JTokenType.Constructor || type == JTokenType.Property || type == JTokenType.Comment;
8373
}
8474
}

0 commit comments

Comments
 (0)