Skip to content

Feature request: add support for mounting PostGraphile's GraphiQL under an express route e.g. /subdir/graphql #753

@devuxer

Description

@devuxer

I'm submitting a ...

  • bug report
  • feature request
  • question

PostGraphile version: 4.0.0b7

Steps to reproduce

Environment variables:

  • "NODE_ENV": "production",
  • "PORT": "3000",
  • "PGHOST": "localhost",
  • "PGPORT": "5432",
  • "PGUSER": "postgres",
  • "PGPASSWORD": "secret",
  • "PGDATABASE": "my_db"

Server code (TypeScript)

import * as express from "express";
import { postgraphile } from "postgraphile";

const app = express();
const router = express.Router();
router.use(postgraphile(undefined, { graphiql: true }));

app.use("/subdir", router); // ** important ** express listens for anything in the "subdir" subdirectory
app.listen(process.env.PORT || 3000);

Current behavior:

When requesting localhost:3000/subdir/graphiql, the page is unable to load its assets due to relative URLs lacking a leading period (.).

Current page source:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>GraphiQL</title>
    <meta name="robots" content="noindex" />
    <link href="/_postgraphile/graphiql/static/css/main.63526d56.css" rel="stylesheet">
</head>
<body>
    <div id="root"></div>
    <script>window.POSTGRAPHILE_CONFIG={graphqlUrl:'/graphql',streamUrl:null}</script>
    <script type="text/javascript" src="/_postgraphile/graphiql/static/js/main.878a1713.js"></script>
</body>
</html>

Expected behavior:

Asset URLs have a leading period (.).

Expected page source:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>GraphiQL</title>
    <meta name="robots" content="noindex" />
    <link href="./_postgraphile/graphiql/static/css/main.63526d56.css" rel="stylesheet">
    <!--        ^ dot added here -->
</head>
<body>
    <div id="root"></div>
    <script>window.POSTGRAPHILE_CONFIG = { graphqlUrl: './graphql', streamUrl: null }</script>
    <!--                                                ^ dot added here -->
    <script type="text/javascript" src="./_postgraphile/graphiql/static/js/main.878a1713.js"></script>
    <!--                                ^ dot added here -->
</body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions