Skip to content

Commit 4759abc

Browse files
committed
send the subscription endpoint as parameter to link creator
1 parent 4c05a53 commit 4759abc

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ interface Tab {
114114
In addition to this, the React app provides some more properties:
115115

116116
- `props` (React Component)
117-
- `createApolloLink` [`(session: Session) => ApolloLink`] - this is the equivalent to the `fetcher` of GraphiQL. For each query that is being executed, this function will be called
117+
- `createApolloLink` [`(session: Session, subscriptionEndpoint?: string) => ApolloLink`] - this is the equivalent to the `fetcher` of GraphiQL. For each query that is being executed, this function will be called
118118

119119
`createApolloLink` is only available in the React Component and not the middlewares, because the content must be serializable as it is being printed into a HTML template.
120120

packages/graphql-playground-react/src/components/Playground.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ export interface Props {
8484
fixedEndpoints: boolean
8585
headers?: any
8686
configPath?: string
87-
createApolloLink?: (session: Session) => ApolloLink
87+
createApolloLink?: (
88+
session: Session,
89+
subscriptionEndpoint?: string,
90+
) => ApolloLink
8891
workspaceName?: string
8992
schema?: GraphQLSchema
9093
}

packages/graphql-playground-react/src/components/PlaygroundWrapper.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export interface PlaygroundWrapperProps {
5757
config?: GraphQLConfig
5858
configPath?: string
5959
injectedState?: any
60-
createApolloLink?: (session: Session) => ApolloLink
60+
createApolloLink?: (
61+
session: Session,
62+
subscriptionEndpoint?: string,
63+
) => ApolloLink
6164
tabs?: Tab[]
6265
schema?: { __schema: any } // introspection result
6366
codeTheme?: EditorColours

packages/graphql-playground-react/src/state/sessions/fetchingSagas.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { safely } from '../../utils'
4040
import { set } from 'immutable'
4141

4242
// tslint:disable
43-
let subscriptionEndpoint = ''
43+
let subscriptionEndpoint
4444

4545
export function setSubscriptionEndpoint(endpoint) {
4646
subscriptionEndpoint = endpoint
@@ -58,7 +58,7 @@ export interface Headers {
5858

5959
export const defaultLinkCreator = (
6060
session: LinkCreatorProps,
61-
wsEndpoint?: string,
61+
subscriptionEndpoint?: string,
6262
): { link: ApolloLink; subscriptionClient?: SubscriptionClient } => {
6363
let connectionParams = {}
6464
const { headers, credentials } = session
@@ -73,20 +73,15 @@ export const defaultLinkCreator = (
7373
credentials,
7474
})
7575

76-
if (!(wsEndpoint || subscriptionEndpoint)) {
76+
if (!subscriptionEndpoint) {
7777
return { link: httpLink }
7878
}
7979

80-
const finalSubscriptionsEndpoint = wsEndpoint || subscriptionEndpoint
81-
82-
const subscriptionClient = new SubscriptionClient(
83-
finalSubscriptionsEndpoint,
84-
{
85-
timeout: 20000,
86-
lazy: true,
87-
connectionParams,
88-
},
89-
)
80+
const subscriptionClient = new SubscriptionClient(subscriptionEndpoint, {
81+
timeout: 20000,
82+
lazy: true,
83+
connectionParams,
84+
})
9085

9186
const webSocketLink = new WebSocketLink(subscriptionClient)
9287
return {
@@ -138,7 +133,7 @@ function* runQuerySaga(action) {
138133
credentials: settings['request.credentials'],
139134
}
140135

141-
const { link, subscriptionClient } = linkCreator(lol)
136+
const { link, subscriptionClient } = linkCreator(lol, subscriptionEndpoint)
142137
yield put(setCurrentQueryStartTime(new Date()))
143138

144139
let firstResponse = false

0 commit comments

Comments
 (0)