Skip to content

Commit 2e839a1

Browse files
author
Raul Hidalgo Caballero
committed
Docs
1 parent bdfb578 commit 2e839a1

File tree

3 files changed

+77
-7
lines changed

3 files changed

+77
-7
lines changed

src/GraphQL.Client/GraphQLClient.cs

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,52 @@
88

99
namespace GraphQL.Client {
1010

11-
public partial class GraphQLClient:IDisposable {
11+
/// <summary>
12+
/// A Client to access GraphQL EndPoints
13+
/// </summary>
14+
public partial class GraphQLClient : IDisposable {
1215

16+
/// <summary>
17+
/// The GraphQL EndPoint to be used
18+
/// </summary>
1319
public Uri EndPoint {
1420
get => this.Options.EndPoint;
1521
set => this.Options.EndPoint = value;
1622
}
1723

24+
/// <summary>
25+
/// The Options to be used
26+
/// </summary>
1827
public GraphQLClientOptions Options { get; set; }
1928

2029
private readonly HttpClient httpClient;
2130

2231
#region Constructors
2332

33+
/// <summary>
34+
/// Initializes a new instance
35+
/// </summary>
36+
/// <param name="endPoint">The EndPoint to be used</param>
2437
public GraphQLClient(string endPoint) : this(new Uri(endPoint)) { }
2538

39+
/// <summary>
40+
/// Initializes a new instance
41+
/// </summary>
42+
/// <param name="endPoint">The EndPoint to be used</param>
2643
public GraphQLClient(Uri endPoint) : this(new GraphQLClientOptions { EndPoint = endPoint }) { }
2744

45+
/// <summary>
46+
/// Initializes a new instance
47+
/// </summary>
48+
/// <param name="endPoint">The EndPoint to be used</param>
49+
/// <param name="options">The Options to be used</param>
2850
public GraphQLClient(string endPoint, GraphQLClientOptions options) : this(new Uri(endPoint), options) { }
2951

52+
/// <summary>
53+
/// Initializes a new instance
54+
/// </summary>
55+
/// <param name="endPoint">The EndPoint to be used</param>
56+
/// <param name="options">The Options to be used</param>
3057
public GraphQLClient(Uri endPoint, GraphQLClientOptions options) {
3158
this.Options = options ?? throw new ArgumentNullException(nameof(options));
3259
this.Options.EndPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
@@ -38,6 +65,10 @@ public GraphQLClient(Uri endPoint, GraphQLClientOptions options) {
3865
this.httpClient = new HttpClient(this.Options.HttpClientHandler);
3966
}
4067

68+
/// <summary>
69+
/// Initializes a new instance
70+
/// </summary>
71+
/// <param name="options">The Options to be used</param>
4172
public GraphQLClient(GraphQLClientOptions options) {
4273
this.Options = options ?? throw new ArgumentNullException(nameof(options));
4374

@@ -51,22 +82,42 @@ public GraphQLClient(GraphQLClientOptions options) {
5182

5283
#endregion
5384

85+
/// <summary>
86+
/// Send a query via GET
87+
/// </summary>
88+
/// <param name="query">The Request</param>
89+
/// <returns>The Response</returns>
5490
public async Task<GraphQLResponse> GetQueryAsync(string query) =>
5591
await this.GetAsync(new GraphQLRequest { Query = query }).ConfigureAwait(false);
5692

57-
public async Task<GraphQLResponse> GetAsync(GraphQLRequest query) {
58-
var queryParamsBuilder = new StringBuilder($"query={query.Query}", 3);
59-
if (query.OperationName != null) { queryParamsBuilder.Append($"&operationName={query.OperationName}"); }
60-
if (query.Variables != null) { queryParamsBuilder.Append($"&variables={JsonConvert.SerializeObject(query.Variables)}"); }
93+
/// <summary>
94+
/// Send a <see cref="GraphQLRequest"/> via GET
95+
/// </summary>
96+
/// <param name="request">The Request</param>
97+
/// <returns>The Response</returns>
98+
public async Task<GraphQLResponse> GetAsync(GraphQLRequest request) {
99+
var queryParamsBuilder = new StringBuilder($"query={request.Query}", 3);
100+
if (request.OperationName != null) { queryParamsBuilder.Append($"&operationName={request.OperationName}"); }
101+
if (request.Variables != null) { queryParamsBuilder.Append($"&variables={JsonConvert.SerializeObject(request.Variables)}"); }
61102
var httpResponseMessage = await this.httpClient.GetAsync($"{this.Options.EndPoint}?{queryParamsBuilder.ToString()}").ConfigureAwait(false);
62103
return await this.ReadHttpResponseMessageAsync(httpResponseMessage).ConfigureAwait(false);
63104
}
64105

106+
/// <summary>
107+
/// Send a query via POST
108+
/// </summary>
109+
/// <param name="query">The Request</param>
110+
/// <returns>The Response</returns>
65111
public async Task<GraphQLResponse> PostQueryAsync(string query) =>
66112
await this.PostAsync(new GraphQLRequest { Query = query }).ConfigureAwait(false);
67113

68-
public async Task<GraphQLResponse> PostAsync(GraphQLRequest query) {
69-
var graphQLString = JsonConvert.SerializeObject(query, this.Options.JsonSerializerSettings);
114+
/// <summary>
115+
/// Send a <see cref="GraphQLRequest"/> via POST
116+
/// </summary>
117+
/// <param name="request">The Request</param>
118+
/// <returns>The Response</returns>
119+
public async Task<GraphQLResponse> PostAsync(GraphQLRequest request) {
120+
var graphQLString = JsonConvert.SerializeObject(request, this.Options.JsonSerializerSettings);
70121
var httpContent = new StringContent(graphQLString, Encoding.UTF8, this.Options.MediaType);
71122
var httpResponseMessage = await this.httpClient.PostAsync(this.EndPoint, httpContent).ConfigureAwait(false);
72123
return await this.ReadHttpResponseMessageAsync(httpResponseMessage).ConfigureAwait(false);
@@ -82,6 +133,9 @@ private async Task<GraphQLResponse> ReadHttpResponseMessageAsync(HttpResponseMes
82133
return JsonConvert.DeserializeObject<GraphQLResponse>(resultString, this.Options.JsonSerializerSettings);
83134
}
84135

136+
/// <summary>
137+
/// Releases unmanaged resources
138+
/// </summary>
85139
public void Dispose() =>
86140
this.httpClient.Dispose();
87141

src/GraphQL.Client/GraphQLClientExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace GraphQL.Client {
66

7+
/// <summary>
8+
/// Extension Methods for <see cref="GraphQLClient"/>
9+
/// </summary>
710
public static class GraphQLClientExtensions {
811

912
private static readonly GraphQLRequest IntrospectionQuery = new GraphQLRequest {
@@ -96,9 +99,19 @@ fragment TypeRef on __Type {
9699
Variables = null
97100
};
98101

102+
/// <summary>
103+
/// Send an IntrospectionQuery via GET
104+
/// </summary>
105+
/// <param name="graphQLClient">The GraphQLClient</param>
106+
/// <returns>The GraphQLResponse</returns>
99107
public static async Task<GraphQLResponse> GetIntrospectionQueryAsync(this GraphQLClient graphQLClient) =>
100108
await graphQLClient.GetAsync(IntrospectionQuery).ConfigureAwait(false);
101109

110+
/// <summary>
111+
/// Send an IntrospectionQuery via POST
112+
/// </summary>
113+
/// <param name="graphQLClient">The GraphQLClient</param>
114+
/// <returns>The GraphQLResponse</returns>
102115
public static async Task<GraphQLResponse> PostIntrospectionQueryAsync(this GraphQLClient graphQLClient) =>
103116
await graphQLClient.PostAsync(IntrospectionQuery).ConfigureAwait(false);
104117

src/GraphQL.Client/GraphQLClientOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace GraphQL.Client {
88

9+
/// <summary>
10+
/// The Options that the <see cref="GraphQLClient"/> will use
11+
/// </summary>
912
public class GraphQLClientOptions {
1013

1114
// TODO Cache

0 commit comments

Comments
 (0)