diff --git a/postgraphiql/src/components/PostGraphiQL.js b/postgraphiql/src/components/PostGraphiQL.js index c178de9fb6..b8dfccd423 100644 --- a/postgraphiql/src/components/PostGraphiQL.js +++ b/postgraphiql/src/components/PostGraphiQL.js @@ -95,13 +95,13 @@ function explainOptionRequiresAnalyze(option) { return ['wal', 'timing'].includes(option); } -function buildExplainOptionsHeader(explainOptions) { +function buildExplainOptionsString(explainOptions) { const analyzeEnabled = explainOptions.analyze; - const validOptions = Object.fromEntries( - Object.entries(explainOptions).filter( - ([option]) => !explainOptionRequiresAnalyze(option) || analyzeEnabled, - ), - ); + const validOptions = analyzeEnabled + ? explainOptions + : Object.fromEntries( + Object.entries(explainOptions).filter(([option]) => !explainOptionRequiresAnalyze(option)), + ); return querystring.stringify(validOptions, ';', '='); } @@ -407,6 +407,7 @@ class PostGraphiQL extends React.PureComponent { */ executeQuery = async graphQLParams => { const extraHeaders = this.getHeaders(); + const explainOpts = buildExplainOptionsString(this.state.explainOptions); const response = await fetch(POSTGRAPHILE_CONFIG.graphqlUrl, { method: 'POST', headers: Object.assign( @@ -414,11 +415,7 @@ class PostGraphiQL extends React.PureComponent { Accept: 'application/json', 'Content-Type': 'application/json', ...(this.state.explain && POSTGRAPHILE_CONFIG.allowExplain - ? { - 'X-PostGraphile-Explain': `on;${buildExplainOptionsHeader( - this.state.explainOptions, - )}`, - } + ? { 'X-PostGraphile-Explain': explainOpts ? `on;${explainOpts}` : 'on' } : null), }, extraHeaders, diff --git a/scripts/dev b/scripts/dev index d5e79ad075..169012528a 100755 --- a/scripts/dev +++ b/scripts/dev @@ -38,7 +38,7 @@ trap 'trap - SIGINT SIGTERM EXIT; JOBS="$(jobs -p)"; [[ "$JOBS" != "" ]] && kill # Run `react-scripts` in the GraphiQL directory as well parallel, but pipe the # output to `/dev/null`. -#(sleep 1 && cd postgraphiql && PORT=5783 node_modules/.bin/react-scripts start) > /dev/null & +(sleep 1 && cd postgraphiql && PORT=5783 node_modules/.bin/react-scripts start) > /dev/null & wait %1 kill %2 diff --git a/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts b/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts index 3c860d79c3..28b9b74907 100644 --- a/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts +++ b/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts @@ -166,7 +166,7 @@ function withPostGraphileContextFromReqResGenerator( jwtToken, pgSettings, explain: explainHeader && explainHeader.on, - explainOptions: explainHeader?.options ?? {}, + explainOptions: (explainHeader && explainHeader.options) || {}, ...moreOptions, }, context => { diff --git a/src/postgraphile/withPostGraphileContext.ts b/src/postgraphile/withPostGraphileContext.ts index 3c9977fd7b..fd48889045 100644 --- a/src/postgraphile/withPostGraphileContext.ts +++ b/src/postgraphile/withPostGraphileContext.ts @@ -502,8 +502,10 @@ export function debugPgClient(pgClient: PoolClient, allowExplain = false): PoolC return null; } const plan = result - .map((r: any) => r[firstKey]) - .map((r: any) => (typeof r === 'string' ? r : JSON.stringify(r, null, 2))) + .map((r: any) => { + const val = r[firstKey]; + return typeof val === 'string' ? val : JSON.stringify(val, null, 2); + }) .join('\n'); return { ...rest,