88
99namespace 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
0 commit comments