Skip to content

Commit d365c54

Browse files
author
Raul Hidalgo Caballero
committed
Check for Null
1 parent 054468b commit d365c54

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/GraphQL.Client/GraphQLClient.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,21 @@ public GraphQLClient(GraphQLClientOptions options) {
8787
/// </summary>
8888
/// <param name="query">The Request</param>
8989
/// <returns>The Response</returns>
90-
public async Task<GraphQLResponse> GetQueryAsync(string query) =>
91-
await this.GetAsync(new GraphQLRequest { Query = query }).ConfigureAwait(false);
90+
public async Task<GraphQLResponse> GetQueryAsync(string query) {
91+
if (query == null) { throw new ArgumentNullException(nameof(query)); }
92+
93+
return await this.GetAsync(new GraphQLRequest { Query = query }).ConfigureAwait(false);
94+
}
9295

9396
/// <summary>
9497
/// Send a <see cref="GraphQLRequest"/> via GET
9598
/// </summary>
9699
/// <param name="request">The Request</param>
97100
/// <returns>The Response</returns>
98101
public async Task<GraphQLResponse> GetAsync(GraphQLRequest request) {
102+
if (request == null) { throw new ArgumentNullException(nameof(request)); }
103+
if (request.Query == null) { throw new ArgumentNullException(nameof(request.Query)); }
104+
99105
var queryParamsBuilder = new StringBuilder($"query={request.Query}", 3);
100106
if (request.OperationName != null) { queryParamsBuilder.Append($"&operationName={request.OperationName}"); }
101107
if (request.Variables != null) { queryParamsBuilder.Append($"&variables={JsonConvert.SerializeObject(request.Variables)}"); }
@@ -108,15 +114,21 @@ public async Task<GraphQLResponse> GetAsync(GraphQLRequest request) {
108114
/// </summary>
109115
/// <param name="query">The Request</param>
110116
/// <returns>The Response</returns>
111-
public async Task<GraphQLResponse> PostQueryAsync(string query) =>
112-
await this.PostAsync(new GraphQLRequest { Query = query }).ConfigureAwait(false);
117+
public async Task<GraphQLResponse> PostQueryAsync(string query) {
118+
if (query == null) { throw new ArgumentNullException(nameof(query)); }
119+
120+
return await this.PostAsync(new GraphQLRequest { Query = query }).ConfigureAwait(false);
121+
}
113122

114123
/// <summary>
115124
/// Send a <see cref="GraphQLRequest"/> via POST
116125
/// </summary>
117126
/// <param name="request">The Request</param>
118127
/// <returns>The Response</returns>
119128
public async Task<GraphQLResponse> PostAsync(GraphQLRequest request) {
129+
if (request == null) { throw new ArgumentNullException(nameof(request)); }
130+
if (request.Query == null) { throw new ArgumentNullException(nameof(request.Query)); }
131+
120132
var graphQLString = JsonConvert.SerializeObject(request, this.Options.JsonSerializerSettings);
121133
var httpContent = new StringContent(graphQLString, Encoding.UTF8, this.Options.MediaType);
122134
var httpResponseMessage = await this.httpClient.PostAsync(this.EndPoint, httpContent).ConfigureAwait(false);

0 commit comments

Comments
 (0)