This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NA): applied changes according pull request review.
feat(NA): applied changes according pull request review.. feat(NA): added static method for instance creation. refact(NA): change the class names back to subscriptionserver and subscriptionclient. feat(NA): applied changes according pull request review. feat(NA): added static method for instance creation. fix(NA): fixed error thrown when we try to print and query its already a string. refact(NA): change the class names back to subscriptionserver and subscriptionclient. feat(NA): added new helper function to fully extend network interface with ws transport. fix(NA): built legacy messages on server side and other bad object accesses. feat(NA): enclose wsclient creation inside addGraphQLWS function.
- Loading branch information
Showing
4 changed files
with
40 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
import { GraphQLTransportWSClient } from './client'; | ||
import { print } from 'graphql/language/printer'; | ||
import { SubscriptionClient, ClientOptions } from './client'; | ||
import { ExecutionResult } from 'graphql'; | ||
|
||
/** | ||
* @deprecated This method becomes deprecated in the new package graphql-transport-ws. | ||
* @deprecated This method will become deprecated in the new package graphql-transport-ws. | ||
* Start using the GraphQLTransportWSClient to make queries, mutations and subscriptions over websockets. | ||
*/ | ||
|
||
// Quick way to add the subscribe and unsubscribe functions to the network interface | ||
export function addGraphQLSubscriptions(networkInterface: any, wsClient: GraphQLTransportWSClient): any { | ||
// We will move this into a new package in the future | ||
export function addGraphQLSubscriptions(networkInterface: any, wsClient: SubscriptionClient): any { | ||
console.warn('This method becomes deprecated in the new package graphql-transport-ws. Start using the ' + | ||
'GraphQLTransportWSClient to make queries, mutations and subscriptions over websockets.'); | ||
|
||
return Object.assign(networkInterface, { | ||
subscribe(request: any, handler: any): number { | ||
return wsClient.subscribe({ | ||
query: print(request.query), | ||
variables: request.variables, | ||
}, handler); | ||
return wsClient.subscribe(request, handler); | ||
}, | ||
unsubscribe(id: number): void { | ||
wsClient.unsubscribe(id); | ||
}, | ||
}); | ||
} | ||
|
||
export function addGraphQLWS(networkInterface: any, wsClientOptions: ClientOptions): any { | ||
if (typeof networkInterface._uri !== 'string') { | ||
throw new Error('Given networkInterface should have an uri defined to config the websocket.'); | ||
} | ||
|
||
const wsClient = new SubscriptionClient(networkInterface._uri, wsClientOptions); | ||
return Object.assign(addGraphQLSubscriptions(networkInterface, wsClient), { | ||
query(request: any): Promise<ExecutionResult> { | ||
return wsClient.query(request); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters