Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: host relative paths for subscriptionsEndpoint option #399

Closed
ksmithut opened this issue May 22, 2017 · 3 comments
Closed

Comments

@ksmithut
Copy link

ksmithut commented May 22, 2017

Intended outcome: Be able to configure GraphiQL with a path (without the protocol, host, or port) for the subscriptionsEndpoint option instead of a fully qualified URL.

Actual outcome: The network interface on the client must have a fully qualified URL, so it throws an error in the client saying that /subscriptions is an invalid.

Uncaught DOMException: Failed to construct 'WebSocket': The URL '/subscriptions' is invalid.

Reproduce

app.use('/graphiql', graphiqlExpress({
  endpointURL: '/graphql',
  subscriptionsEndpoint: '/subscriptions' // Note this being relative
})

I think this can be done by leveraging window.location, but it would require some code branching and detection of whether or not the passed url is host relative or not. Plus, you'd kind of be forced to make a decision of what the default protocol would be, like should you always use wss:// if window.location.protocol === 'https:', and should you use the same port. I believe that kind of default configuration would be acceptable, but I'd understand if it's something you'd rather not force an opinion on.

Here's the reasoning. I like my server configuration to not really care about the environment it's hosted in. For example, In some setups, I have a single server handling requests for multiple servers, like tenant1.example.com and tenant2.example.com, and I'd like both of them to have a /graphiql that support subscriptions, but I can't do that with the current options model.

Anyway, feel free to close this if you don't want to support this.

@pho3nixf1re
Copy link

I am currently in need of this feature as well. If a PR would be accepted using the strategy @ksmithut suggests above then I can work on this. Before I work on that I would want feedback from the maintainers here.

@helfer
Copy link
Contributor

helfer commented Jun 28, 2017

Should be possible now with #418.

@helfer helfer closed this as completed Jun 28, 2017
@ksmithut
Copy link
Author

ksmithut commented Jul 4, 2017

For posterity, this is now possible:

app.use('/graphiql', graphiqlExpress(req => ({
  endpointURL: '/graphql',
  subscriptionsEndpoint: url.format({
    host: req.get('host'),
    protocol: req.protocol === 'https' ? 'wss' : 'ws',
    pathname: '/subscriptions'
  })
})))

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants