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

feat(graphiql): Set 'X-GraphQL-Event-Stream' header when --watch enabled #728

Merged
merged 4 commits into from
Mar 29, 2018
Merged
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
2 changes: 1 addition & 1 deletion scripts/dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $npm_bin/nodemon \
--ignore __mocks__ \
--ignore src/postgraphile/graphiql \
--ext js,ts \
--exec "$npm_bin/ts-node --ignore node_modules --disableWarnings src/postgraphile/cli.ts --schema a,b,c --show-error-stack json --watch $@" &
--exec "$npm_bin/ts-node --ignore node_modules --disableWarnings src/postgraphile/cli.ts --show-error-stack json --extended-errors hint,detail,errcode $@" &

# Ensure forked process is killed even if we die unexpectedly
trap 'trap - SIGINT SIGTERM EXIT; JOBS="$(jobs -p)"; [[ "$JOBS" != "" ]] && kill $JOBS 2>/dev/null || true' SIGINT SIGTERM EXIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export default function createPostGraphileHttpRequestHandler(options) {

// Setup an event stream so we can broadcast events to graphiql, etc.
if (parseUrl(req).pathname === '/_postgraphile/stream') {
if (req.headers.accept !== 'text/event-stream') {
if (!options.watchPg || req.headers.accept !== 'text/event-stream') {
res.statusCode = 405
res.end()
return
Expand Down Expand Up @@ -339,6 +339,11 @@ export default function createPostGraphileHttpRequestHandler(options) {

// If we didn’t call `next` above, all requests will return 200 by default!
res.statusCode = 200
if (options.watchPg) {
// Inform GraphiQL and other clients that they can subscribe to events
// (such as the schema being updated) at the following URL
res.setHeader('X-GraphQL-Event-Stream', '/_postgraphile/stream')
}

// Don’t execute our GraphQL stuffs for `OPTIONS` requests.
if (req.method === 'OPTIONS') {
Expand Down