Repository: graphql/graphql-playground

Issue #220: Support options being passed as function to be called with context
Created: 2017-11-08T22:11:59Z
This issue pertains to:

 GraphQL Playground - Electron App
 GraphQL Playground

What OS and OS version are you experiencing the issue(s) on?
N/A
What version of graphql-playground(-electron) are you experience the issue(s) on?
graphql-playground-middleware-express@1.1.2
What is the expected behavior?
Be able to pass a function as the options parameter and be able to return the options based on values in the request. The real issue is the 'subscriptionEndpoint' has to be a fully qualified host with path, and I would like to just pass the path, i.e. '/subscriptions', but because it expects the full host and I'm hosting this on a server that accepts requests from multiple hosts (subdomains), I need to dynamically give the subscriptions endpoint the host. I believe this could happen on the client, taking the window.location object and getting the host information and prepending the path. I have the same issue with graphiql-express, but they allow you to pass in the options via a function that returns the options, like this
What is the actual behavior?
It only accepts a flat function.
What steps may we take to reproduce the behavior?
const url = require('url')
const express = require('express')
const expressPlayground = require('graphql-playground-middleware-express')
const app = express()

app.use('/playground1', expressPlayground({
  endpoint: '/graphql',
  subscriptionEndpoint: '/subscriptions' // I hoped this would work
})

app.use('/playground2', expressPlayground((req) => ({
  endpoint: '/graphql',
  subscriptionEndpoint: url.format({ // I'm okay with this, but would prefer option above
    host: req.get('host'),
    protocol: req.protocol === 'https' ? 'wss' : 'ws',
    slashes: true,
    pathname: '/subscriptions'
  })
}))

// How I'm currently getting around it
app.use('/playground3', (req, res, next) => {
  expressPlayground({
    endpoint: '/graphql',
    subscriptionEndpoint: url.format({
      host: req.get('host'),
      protocol: req.protocol === 'https' ? 'wss' : 'ws',
      slashes: true,
      pathname: '/subscriptions'
    })
  })(req, res, next)
})
I'd be happy to submit a PR for it, I'm just unsure which direction you'd want to take it.

Duplicate issue #358: [bug] subscriptionEndpoint ignored on graphql-playground-middleware-koa@>=1.3.5
Created: 2017-12-17T10:35:30Z
This issue pertains to the following package(s):

 GraphQL Playground - Electron App
 GraphQL Playground HTML
 GraphQL Playground
 GraphQL Playground Express Middleware
 GraphQL Playground Hapi Middleware
 GraphQL Playground Koa Middleware
 GraphQL Playground Lambda Middleware

What OS and OS version are you experiencing the issue(s) on?
window + linux
What version of graphql-playground(-electron/-middleware) are you experiencing the issue(s) on?
graphql-playground-middleware-koa  1.3.5 and 1.3.6,
What is the expected behavior?
subscriptionEndpoint: '/subscriptions' should cause the server to connect to the specific path
What is the actual behavior?
server tries to connect to websocket on path graphql (regular endpoint)
(note this worked fine with graphql-playground-middleware-koa@1.3.1)

Closing comment (2017-12-17T10:35:55Z): possibly related to #220