Normalize subscriptions endpoint in graphiql_source
(#628)
The objective here is to make the Playground and GraphiQL have the same behavior with the endpoint arguments.
This commit is contained in:
parent
5cf21bf41b
commit
40ad17c540
2 changed files with 20 additions and 1 deletions
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
- Normalization for the subscriptions_endpoint_url in the `graphiql_source`.
|
||||||
|
(See [#628](https://github.com/graphql-rust/juniper/pull/628) for more details)
|
||||||
|
|
||||||
- Support raw identifiers in field and argument names. (`#[object]` macro)
|
- Support raw identifiers in field and argument names. (`#[object]` macro)
|
||||||
|
|
||||||
- Most error types now implement `std::error::Error`:
|
- Most error types now implement `std::error::Error`:
|
||||||
|
|
|
@ -31,7 +31,23 @@ pub fn graphiql_source(
|
||||||
let fetcher_source = r#"
|
let fetcher_source = r#"
|
||||||
<script>
|
<script>
|
||||||
if (usingSubscriptions) {
|
if (usingSubscriptions) {
|
||||||
var subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient(GRAPHQL_SUBSCRIPTIONS_URL, { reconnect: true });
|
var subscriptionEndpoint = normalizeSubscriptionEndpoint(GRAPHQL_URL, GRAPHQL_SUBSCRIPTIONS_URL);
|
||||||
|
var subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient(subscriptionEndpoint, { reconnect: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeSubscriptionEndpoint(endpoint, subscriptionEndpoint) {
|
||||||
|
if (subscriptionEndpoint) {
|
||||||
|
if (subscriptionEndpoint.startsWith('/')) {
|
||||||
|
const secure =
|
||||||
|
endpoint.includes('https') || location.href.includes('https')
|
||||||
|
? 's'
|
||||||
|
: ''
|
||||||
|
return `ws${secure}://${location.host}${subscriptionEndpoint}`
|
||||||
|
} else {
|
||||||
|
return subscriptionEndpoint.replace(/^http/, 'ws')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
function graphQLFetcher(params) {
|
function graphQLFetcher(params) {
|
||||||
|
|
Loading…
Reference in a new issue