@@ -15,15 +15,14 @@ public class GraphQLClient
1515 {
1616 public readonly List < Query > SearchableQueries ;
1717 public readonly Dictionary < string , string > CustomHeaders ;
18-
1918 public string Endpoint ;
2019 public string AuthScheme ;
2120
2221 public GraphQLClient (
2322 string endpoint ,
24- string authScheme = "Bearer" ,
2523 IEnumerable < Query > queries = null ,
26- Dictionary < string , string > headers = null
24+ Dictionary < string , string > headers = null ,
25+ string authScheme = null
2726 )
2827 {
2928 Endpoint = endpoint ;
@@ -35,36 +34,26 @@ public GraphQLClient(
3534 public GraphQLClient ( GraphQLConfig config )
3635 {
3736 Endpoint = config . Endpoint ;
38- AuthScheme = config . AuthScheme ;
3937 SearchableQueries = config . Files . SelectMany ( x => x . Queries ) . ToList ( ) ;
4038 CustomHeaders = config . CustomHeaders . ToDictionary ( header => header . Key , header => header . Value ) ;
41- }
42-
43- public async Task < string > SendAsync (
44- Query query ,
45- string authToken = null ,
46- Dictionary < string , object > variables = null ,
47- Dictionary < string , string > headers = null
48- )
49- {
50- return await SendAsync ( query , AuthScheme , authToken , variables , headers ) ;
39+ AuthScheme = config . AuthScheme ;
5140 }
5241
5342 /// <summary>
5443 /// Send a query!
5544 /// </summary>
5645 /// <param name="query">The query you are sending. These should be generated from your graphQL files.</param>
57- /// <param name="authScheme">The authScheme to be used.</param>
58- /// <param name="authToken">The authToken</param>
5946 /// <param name="variables">Any variables you want to pass</param>
6047 /// <param name="headers">Any headers you want to pass</param>
48+ /// <param name="authToken">The authToken</param>
49+ /// <param name="authScheme">The authScheme to be used.</param>
6150 /// <returns></returns>
6251 public async Task < string > SendAsync (
6352 Query query ,
64- string authScheme = "Bearer" ,
65- string authToken = null ,
6653 Dictionary < string , object > variables = null ,
67- Dictionary < string , string > headers = null
54+ Dictionary < string , string > headers = null ,
55+ string authToken = null ,
56+ string authScheme = null
6857 )
6958 {
7059 if ( query . OperationType == OperationType . Subscription )
@@ -83,12 +72,18 @@ public async Task<string> SendAsync(
8372 }
8473 }
8574
75+ if ( authScheme == null )
76+ {
77+ authScheme = AuthScheme ;
78+ }
79+
8680 string postQueryAsync = await HttpUtils . PostQueryAsync (
8781 Endpoint ,
8882 query ,
89- AuthScheme ,
83+ variables ,
84+ headers ,
9085 authToken ,
91- variables , headers
86+ authScheme
9287 ) ;
9388
9489 return postQueryAsync ;
@@ -102,11 +97,11 @@ public void RegisterListener(Action<string> listener)
10297 {
10398 HttpUtils . SubscriptionDataReceived += listener ;
10499 }
100+
105101 /// <summary>
106102 /// Unregisters a listener for subscriptions.
107103 /// </summary>
108104 /// <param name="listener"></param>
109-
110105 public void UnregisterListener ( Action < string > listener )
111106 {
112107 HttpUtils . SubscriptionDataReceived -= listener ;
@@ -116,26 +111,17 @@ public void UnregisterListener(Action<string> listener)
116111 /// Subscribe to a query in GraphQL.
117112 /// </summary>
118113 /// <param name="query"></param>
119- /// <param name="authToken"></param>
120114 /// <param name="variables"></param>
121115 /// <param name="headers"></param>
116+ /// <param name="authToken"></param>
117+ /// <param name="authScheme"></param>
122118 /// <returns>True if successful</returns>
123119 public async Task < bool > SubscribeAsync (
124120 Query query ,
125- string authToken = null ,
126121 Dictionary < string , object > variables = null ,
127- Dictionary < string , string > headers = null
128- )
129- {
130- return await SubscribeAsync ( query , AuthScheme , authToken , variables , headers ) ;
131- }
132-
133- public async Task < bool > SubscribeAsync (
134- Query query ,
135- string authScheme = "Bearer" ,
122+ Dictionary < string , string > headers = null ,
136123 string authToken = null ,
137- Dictionary < string , object > variables = null ,
138- Dictionary < string , string > headers = null
124+ string authScheme = null
139125 )
140126 {
141127 if ( query . OperationType != OperationType . Subscription )
@@ -154,10 +140,15 @@ public async Task<bool> SubscribeAsync(
154140 }
155141 }
156142
143+ if ( authScheme == null )
144+ {
145+ authScheme = AuthScheme ;
146+ }
147+
157148 if ( ! HttpUtils . IsWebSocketReady ( ) )
158149 {
159150 // Prepare the socket before continuing.
160- await HttpUtils . WebSocketConnect ( Endpoint , authScheme , authToken , "graphql-ws" , headers ) ;
151+ await HttpUtils . WebSocketConnect ( Endpoint , "graphql-ws" , headers , authToken , authScheme ) ;
161152 }
162153
163154 return await HttpUtils . WebSocketSubscribe ( query . ToString ( ) , query , variables ) ;
@@ -191,7 +182,7 @@ public Query FindQuery(string fileName)
191182 /// <summary>
192183 /// Finds the first query located in a file.
193184 /// </summary>
194- /// <param name="fileName "></param>
185+ /// <param name="operationName "></param>
195186 /// <returns></returns>
196187 public Query FindQueryByOperation ( string operationName )
197188 {
@@ -212,7 +203,6 @@ public Query FindQuery(string fileName, string operationName)
212203 /// <summary>
213204 /// Finds a query by operationName and operationType.
214205 /// </summary>
215- /// <param name="fileName"></param>
216206 /// <param name="operationName"></param>
217207 /// <param name="operationType"></param>
218208 /// <returns></returns>
0 commit comments