@@ -39,18 +39,30 @@ export class NetworkHelper {
39
39
endpoint : Endpoint
40
40
updateCallback : ( data : string , operation : string ) => void
41
41
} ) {
42
- const wsEndpointURL = endpoint . url . replace ( / ^ h t t p / , "ws" )
43
- const wsClient = createWSClient ( {
44
- url : wsEndpointURL ,
45
- connectionAckWaitTimeout : 3000 ,
46
- webSocketImpl : ws ,
47
- } )
48
-
49
42
const { rejectUnauthorized } = workspace . getConfiguration ( "vscode-graphql" )
50
43
// this is a node specific setting that can allow requests against servers using self-signed certificates
51
44
// it is similar to passing the nodejs env variable flag, except configured on a per-request basis here
52
45
const agent = new Agent ( { rejectUnauthorized } )
53
46
47
+ const exchanges = [ ...defaultExchanges ] ;
48
+ if ( operation === "subscription" ) {
49
+ const wsEndpointURL = endpoint . url . replace ( / ^ h t t p / , "ws" )
50
+ const wsClient = createWSClient ( {
51
+ url : wsEndpointURL ,
52
+ connectionAckWaitTimeout : 3000 ,
53
+ webSocketImpl : ws ,
54
+ } )
55
+ exchanges . push (
56
+ subscriptionExchange ( {
57
+ forwardSubscription : operation => ( {
58
+ subscribe : sink => ( {
59
+ unsubscribe : wsClient . subscribe ( operation , sink ) ,
60
+ } ) ,
61
+ } ) ,
62
+ } ) ,
63
+ )
64
+ }
65
+
54
66
return createClient ( {
55
67
url : endpoint . url ,
56
68
fetch,
@@ -60,16 +72,7 @@ export class NetworkHelper {
60
72
// @ts -expect-error
61
73
agent,
62
74
} ,
63
- exchanges : [
64
- ...defaultExchanges ,
65
- subscriptionExchange ( {
66
- forwardSubscription : operation => ( {
67
- subscribe : sink => ( {
68
- unsubscribe : wsClient . subscribe ( operation , sink ) ,
69
- } ) ,
70
- } ) ,
71
- } ) ,
72
- ] ,
75
+ exchanges,
73
76
} )
74
77
}
75
78
0 commit comments