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

Subscriptions: support custom WebSockets path via subscription.wsPath option #1130

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
- `subscription.onDisconnect`: `Function` A function which is called with the subscription context of the connection after the connection gets disconnected.
- `subscription.keepAlive`: `Integer` Optional interval in ms to send the `GQL_CONNECTION_KEEP_ALIVE` message.
- `subscription.fullWsTransport`: `Boolean` Enable sending every operation via WS.
- `subscription.wsPath`: `String` Optional. Change default graphql websockets route (see `path` above) to another one.

- `persistedQueries`: A hash/query map to resolve the full query text using it's unique hash. Overrides `persistedQueryProvider`.
- `onlyPersisted`: Boolean. Flag to control whether to allow graphql queries other than persisted. When `true`, it'll make the server reject any queries that are not present in the `persistedQueries` option above. It will also disable any ide available (graphiql). Requires `persistedQueries` to be set, and overrides `persistedQueryProvider`.
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const mercurius = fp(async function (app, opts) {
let onDisconnect
let keepAlive
let fullWsTransport
let wsPath

if (typeof subscriptionOpts === 'object') {
if (subscriptionOpts.pubsub) {
Expand All @@ -141,6 +142,7 @@ const mercurius = fp(async function (app, opts) {
onDisconnect = subscriptionOpts.onDisconnect
keepAlive = subscriptionOpts.keepAlive
fullWsTransport = subscriptionOpts.fullWsTransport
wsPath = subscriptionOpts.path
} else if (subscriptionOpts === true) {
emitter = mq()
subscriber = new PubSub(emitter)
Expand Down Expand Up @@ -211,6 +213,7 @@ const mercurius = fp(async function (app, opts) {
subscriptionContextFn,
keepAlive,
fullWsTransport,
wsPath,
additionalRouteOptions: opts.additionalRouteOptions
})
}
Expand Down
3 changes: 2 additions & 1 deletion lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ module.exports = async function (app, opts) {
fullWsTransport,
additionalRouteOptions
} = opts
const wsPath = opts.wsPath || graphqlPath

// Load the persisted query settings
const {
Expand Down Expand Up @@ -325,7 +326,7 @@ module.exports = async function (app, opts) {

if (subscriber) {
app.register(subscription, {
getOptions,
getOptions: { ...getOptions, url: wsPath },
subscriber,
verifyClient,
onConnect,
Expand Down