8
8
* - updating variables in the event of changes in the config files
9
9
* @changelog : Austin Ruby, Nov. 15th: passed invocation of RFSRWR function within doc
10
10
* save listener into debounce function to avoid overquerying API if user mashes save
11
+ * @changelog : Austin Ruby, Nov. 22nd:
12
+ * - added instructions for adding external server url to config file comments
13
+ * - added logic to not invoke serverOn if using external server
14
+ * - added logic to call RFSRWR if using external server
15
+ * - added url argument to RFSRWR -- undefined if locally hosted server, otherwise
16
+ * will be the url of the server
17
+ * - accounted for external url on deactivation
11
18
* * */
12
19
13
20
// eslint-disable-next-line import/no-unresolved
@@ -96,10 +103,11 @@ export function activate(context: vscode.ExtensionContext) {
96
103
// Check ONCE if the port is open (also this does not need the third param)
97
104
// will resolve to a true or false value
98
105
const serverOnFromUser = await checkForRunningServer ( portNumber , true ) ;
99
- // console.log('--serverOnFromUser after once check is:', serverOnFromUser) ;
106
+ const externalURL = entryPoint . slice ( 0 , 4 ) === 'http' ;
100
107
101
108
// trigger serverOn if the user does not already have the server running
102
- if ( ! serverOnFromUser ) {
109
+ // AND if the server is not hosted at an external URL
110
+ if ( ! serverOnFromUser && ! externalURL ) {
103
111
// start up the user's server, pass in the gqChannel to log any error messages
104
112
serverOn ( entryPoint , gqChannel ) ;
105
113
@@ -133,16 +141,20 @@ export function activate(context: vscode.ExtensionContext) {
133
141
}
134
142
}
135
143
136
- // if the server is on from either the user or graphquill, continue
137
- // send first query & setup on save listener
138
- if ( serverOnFromUser || serverTurnedOnByGraphQuill ) {
139
- // update isOnToggle (refers to state of GraphQuill extension running or not)
144
+ // if the server is on from either the user or graphquill,
145
+ // or the user is querying an external URL,
146
+ // continue and send first query & setup on save listener
147
+ if ( serverOnFromUser || serverTurnedOnByGraphQuill || externalURL ) {
148
+ let url : ( undefined | string ) ;
149
+ // if user's server is running at external url, set url to their specified entryPoint
150
+ if ( externalURL ) url = entryPoint ;
151
+ // make isOnToggle true regardless of url to enable deactivation functionality
140
152
isOnToggle = true ;
141
153
142
154
// get the fileName of the open file when the extension is FIRST fired
143
155
const currOpenEditorPath : string = vscode . window . activeTextEditor ! . document . fileName ;
144
156
// send that request from the currentopeneditor
145
- readFileSendReqAndWriteResponse ( currOpenEditorPath , gqChannel , portNumber , rootPath ) ;
157
+ readFileSendReqAndWriteResponse ( currOpenEditorPath , gqChannel , portNumber , rootPath , url ) ;
146
158
147
159
148
160
const debouncedRFSRWR = debounce (
@@ -171,7 +183,7 @@ export function activate(context: vscode.ExtensionContext) {
171
183
}
172
184
173
185
// send the filename and channel to the readFileSRAWR function
174
- debouncedRFSRWR ( event . fileName , gqChannel , portNumber , rootPath ) ;
186
+ debouncedRFSRWR ( event . fileName , gqChannel , portNumber , rootPath , url ) ;
175
187
176
188
// satisfying linter
177
189
return null ;
@@ -193,6 +205,7 @@ export function activate(context: vscode.ExtensionContext) {
193
205
// console.log('--deactivate functionality triggered');
194
206
195
207
// check isontoggle boolean
208
+ // as long as user isn't querying external URL
196
209
if ( ! isOnToggle ) {
197
210
// server is already off
198
211
// console.log('server is already off');
@@ -261,7 +274,7 @@ export function activate(context: vscode.ExtensionContext) {
261
274
// if it does not already exist, write to a new file
262
275
fs . writeFileSync ( graphQuillConfigPath ,
263
276
// string to populate the file with
264
- 'module.exports = {\n // change "./server/index.js" to the relative path from the root directory to\n // the file that starts your server\n entry: \'./server/index.js\',\n\n // change 3000 to the port number that your server runs on\n portNumber: 3000,\n\n // to increase the amount of time allowed for the server to startup, add a time\n // in milliseconds (integer) to the "serverStartupTimeAllowed"\n // serverStartupTimeAllowed: 5000,\n};\n' ,
277
+ 'module.exports = {\n // change "./server/index.js" to the relative path from the root directory to\n // the file that starts your server.\n // if you\'re connecting to an external server,\n // change "./server/index.js" to its URL in the following format:\n // "https://yourserverurl.com" \n entry: \'./server/index.js\',\n\n // change 3000 to the port number that your server runs on\n portNumber: 3000,\n\n // to increase the amount of time allowed for the server to startup, add a time\n // in milliseconds (integer) to the "serverStartupTimeAllowed"\n // serverStartupTimeAllowed: 5000,\n};\n' ,
265
278
'utf-8' ) ;
266
279
267
280
// open the file in vscode
@@ -276,6 +289,9 @@ export function activate(context: vscode.ExtensionContext) {
276
289
// push it to the subscriptions
277
290
context . subscriptions . push ( disposableCreateConfigFile ) ;
278
291
292
+ /** **************************************************************************
293
+ * * Fifth GraphQuill option in command palette to SHOW THE SCHEMA
294
+ ************************************************************************** */
279
295
const disposableShowGraphQLSchema = vscode . commands . registerCommand ( 'extension.showGraphQLSchema' , async ( ) => {
280
296
// console.log('show schema running');
281
297
// show output channel, clear any old stuff off of it
@@ -300,11 +316,13 @@ export function activate(context: vscode.ExtensionContext) {
300
316
// Check ONCE if the port is open (also this does not need the third param)
301
317
// will resolve to a true or false value
302
318
const serverOnAlready = await checkForRunningServer ( portNumber , true ) ;
319
+ const externalURL = entryPoint . slice ( 0 , 4 ) === 'http' ;
303
320
// console.log('--serverOnFromUser after once check is:', serverOnFromUser);
304
321
let serverTurnedOnBySchemaOutputter = false ;
305
322
306
323
// trigger serverOn if the user does not already have the server running
307
- if ( ! serverOnAlready ) {
324
+ // or if user is requesting data from external server
325
+ if ( ! serverOnAlready && ! externalURL ) {
308
326
// start up the user's server, pass in the gqChannel to log any error messages
309
327
serverOn ( entryPoint , gqChannel ) ;
310
328
@@ -337,12 +355,14 @@ export function activate(context: vscode.ExtensionContext) {
337
355
return setTimeout ( ( ) => serverOff ( portNumber ) , 5000 ) ;
338
356
}
339
357
}
340
-
358
+ let url : ( undefined | string ) ;
359
+ if ( externalURL ) url = entryPoint ;
360
+ // console.log('before invoking showSchema: ', url);
341
361
// clear the channel off?
342
362
gqChannel . clear ( ) ;
343
363
344
364
// run required in functionality here, required in
345
- showGraphqlSchema ( serverOnAlready , serverTurnedOnBySchemaOutputter , gqChannel , portNumber ) ;
365
+ showGraphqlSchema ( serverOnAlready , serverTurnedOnBySchemaOutputter , gqChannel , portNumber , url ) ;
346
366
347
367
// turn the server off if the extension turned it on
348
368
// eslint-disable-next-line max-len
0 commit comments