@@ -33,6 +33,7 @@ function Client(config) {
3333 this . config = config ;
3434 this . baseUrl = config . baseUrl ;
3535 this . entryPoint = undefined ;
36+ this . tenantId = undefined ;
3637
3738 this . oauth2 = oauth2 . create ( {
3839 client : {
@@ -136,8 +137,26 @@ Client.prototype.setAccessToken = function(callback) {
136137 */
137138Client . prototype . setEntryPoint = function ( entryPoint ) {
138139 debug ( 'updating entry point' ) ;
140+ this . entryPoint = entryPoint ;
139141 // a trick to support different entry points in node-upwork
140- this . baseUrl = this . baseUrl . replace ( / \/ a p i \/ / i, '/' + entryPoint + '/' ) ;
142+ if ( entryPoint === 'graphql' ) {
143+ this . baseUrl = this . config . gqlUrl ;
144+ } else {
145+ this . baseUrl = this . baseUrl . replace ( / \/ a p i \/ / i, '/' + entryPoint + '/' ) ;
146+ }
147+ }
148+
149+ /**
150+ * Configure X-Upwork-API-TenantId header
151+ *
152+ * @method setOrgUidHeader
153+ * @param tenantId {String} Organization UID
154+ * @param callback
155+ * @async
156+ */
157+ Client . prototype . setOrgUidHeader = function ( tenantId , callback ) {
158+ debug ( 'setting organization uid header' ) ;
159+ this . tenantId = tenantId ;
141160}
142161
143162/**
@@ -215,7 +234,9 @@ Client.prototype.sendRequest = function (method, url, params, callback) {
215234 _params = { qs : params } ;
216235 break ;
217236 case 'POST' :
218- _params = { formData : params } ;
237+ if ( this . entryPoint !== 'graphql' ) {
238+ _params = { formData : params } ;
239+ }
219240 break ;
220241 default :
221242 _params = { formData : Object . assign ( params , { http_method : method . toLowerCase ( ) } ) } ;
@@ -232,6 +253,14 @@ Client.prototype.sendRequest = function (method, url, params, callback) {
232253 'User-Agent' : UpworkLibraryUserAgent
233254 }
234255 } ;
256+ // GraphQL support
257+ if ( this . entryPoint === 'graphql' ) {
258+ if ( this . tenantId !== undefined ) {
259+ _options . headers [ 'X-Upwork-API-TenantId' ] = this . tenantId ;
260+ }
261+ _options . headers [ 'Content-Type' ] = 'application/json' ;
262+ _options . body = JSON . stringify ( params ) ;
263+ }
235264
236265 request ( Object . assign ( _options , _params ) , ( err , httpResponse , body ) => {
237266 callback ( err , httpResponse . statusCode , parseResponse ( body ) ) ;
0 commit comments