55
66namespace GraphQLSharp ;
77
8- public class GraphQLClient < TQueryRoot , TMutationRoot , TClientOptions > : GraphQLClient < TQueryRoot , TClientOptions >
8+ public class GraphQLClient < TGraphQLRequest , TClientOptions , TQueryRoot , TMutationRoot > : GraphQLClient < TGraphQLRequest , TClientOptions , TQueryRoot >
9+ where TGraphQLRequest : GraphQLRequest , new ( )
910 where TQueryRoot : class
1011 where TMutationRoot : class
1112 where TClientOptions : GraphQLClientOptions
@@ -19,13 +20,14 @@ public Task<GraphQLResponse<TMutationRoot>> ExecuteMutationAsync([StringSyntax("
1920 return ExecuteAsync < TMutationRoot > ( query , options , cancellationToken ) ;
2021 }
2122
22- public Task < GraphQLResponse < TMutationRoot > > ExecuteMutationAsync ( GraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
23+ public Task < GraphQLResponse < TMutationRoot > > ExecuteMutationAsync ( TGraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
2324 {
2425 return ExecuteAsync < TMutationRoot > ( request , options , cancellationToken ) ;
2526 }
2627}
2728
28- public class GraphQLClient < TQueryRoot , TClientOptions > : GraphQLClient < TClientOptions >
29+ public class GraphQLClient < TGraphQLRequest , TClientOptions , TQueryRoot > : GraphQLClient < TGraphQLRequest , TClientOptions >
30+ where TGraphQLRequest : GraphQLRequest , new ( )
2931 where TQueryRoot : class
3032 where TClientOptions : GraphQLClientOptions
3133{
@@ -38,25 +40,26 @@ public Task<GraphQLResponse<TQueryRoot>> ExecuteQueryAsync([StringSyntax("GraphQ
3840 return ExecuteAsync < TQueryRoot > ( query , options , cancellationToken ) ;
3941 }
4042
41- public Task < GraphQLResponse < TQueryRoot > > ExecuteQueryAsync ( GraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
43+ public Task < GraphQLResponse < TQueryRoot > > ExecuteQueryAsync ( TGraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
4244 {
4345 return ExecuteAsync < TQueryRoot > ( request , options , cancellationToken ) ;
4446 }
4547}
4648
47- public class GraphQLCLient : GraphQLClient < GraphQLClientOptions >
49+ public class GraphQLCLient : GraphQLClient < GraphQLRequest , GraphQLClientOptions >
4850{
4951 public GraphQLCLient ( GraphQLClientOptions defaultOptions = null ) : base ( defaultOptions )
5052 {
5153 }
5254}
5355
54- public class GraphQLClient < TClientOptions >
56+ public class GraphQLClient < TGraphQLRequest , TClientOptions >
57+ where TGraphQLRequest : GraphQLRequest , new ( )
5558 where TClientOptions : GraphQLClientOptions
5659{
5760 private static readonly HttpClient _defaultHttpClient = new ( ) ;
5861
59- private static readonly ProductInfoHeaderValue _defaultUserAgent = new ( typeof ( GraphQLClient < TClientOptions > ) . Assembly . GetName ( ) . Name ! , typeof ( GraphQLClient < TClientOptions > ) . Assembly . GetName ( ) . Version ! . ToString ( ) ) ;
62+ private static readonly ProductInfoHeaderValue _defaultUserAgent = new ( typeof ( GraphQLClient < TGraphQLRequest , TClientOptions > ) . Assembly . GetName ( ) . Name ! , typeof ( GraphQLClient < TGraphQLRequest , TClientOptions > ) . Assembly . GetName ( ) . Version ! . ToString ( ) ) ;
6063
6164 private readonly TClientOptions _defaultOptions ;
6265
@@ -75,16 +78,16 @@ public Task<GraphQLResponse<JsonElement>> ExecuteAsync([StringSyntax("GraphQL")]
7578
7679 public Task < GraphQLResponse < T > > ExecuteAsync < T > ( [ StringSyntax ( "GraphQL" ) ] string query , TClientOptions options = null , CancellationToken cancellationToken = default )
7780 {
78- return ExecuteAsync < T > ( new GraphQLRequest { query = query } , options , cancellationToken ) ;
81+ return ExecuteAsync < T > ( new TGraphQLRequest { query = query } , options , cancellationToken ) ;
7982 }
8083
81- public Task < GraphQLResponse < JsonElement > > ExecuteAsync ( GraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
84+ public Task < GraphQLResponse < JsonElement > > ExecuteAsync ( TGraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
8285 {
8386 //returing JsonElement and not JsonDocument because JsonDocument is disposable and we don't want to force the user to dispose it
8487 return ExecuteAsync < JsonElement > ( request , options , cancellationToken ) ;
8588 }
8689
87- public async Task < GraphQLResponse < T > > ExecuteAsync < T > ( GraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
90+ public async Task < GraphQLResponse < T > > ExecuteAsync < T > ( TGraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
8891 {
8992 var interceptor = options ? . Interceptor ?? _defaultOptions ? . Interceptor ?? DefaultInterceptor ;
9093
@@ -100,7 +103,7 @@ public async Task<GraphQLResponse<T>> ExecuteAsync<T>(GraphQLRequest request, TC
100103 }
101104 }
102105
103- private async Task < GraphQLResponse < T > > ExecuteCoreAsync < T > ( GraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
106+ private async Task < GraphQLResponse < T > > ExecuteCoreAsync < T > ( TGraphQLRequest request , TClientOptions options = null , CancellationToken cancellationToken = default )
104107 {
105108 HttpResponse httpResponse = null ;
106109 try
@@ -151,8 +154,9 @@ protected virtual void ValidateOptions(TClientOptions defaultOptions, TClientOpt
151154 {
152155 }
153156
154- private HttpRequestMessage CreateHttpRequest ( GraphQLRequest request , TClientOptions options )
157+ private HttpRequestMessage CreateHttpRequest ( TGraphQLRequest request , TClientOptions options )
155158 {
159+ _ = request . query ?? throw new ArgumentNullException ( nameof ( request . query ) ) ;
156160 ValidateOptions ( _defaultOptions , options ) ;
157161 var uri = options ? . Uri ?? _defaultOptions ? . Uri ?? throw new ArgumentNullException ( $ "{ nameof ( options ) } .{ nameof ( options . Uri ) } ") ;
158162 var requestMessage = new HttpRequestMessage
0 commit comments