I'm trying to proxy requests to postgraphql and its igraphql server. I have a reverse proxy similar to Nginx which is proxying paths which begin with /analytics to the postgraphql server. The problem is that some of the static file references in the HTML for igraphql are referenced as /_postgraphql/* and I am unable to change the reverse proxy to also send me requests for /_postgraphql/*. Is it possible to make the URLs referencing /_postgraphql/* relative or add a prefix in front of them to help those of us using reverse proxies?
From a quick search it looks like only 4 files reference _postgraphql; I'd be happy to accept a pull request that achieved your goal cleanly.
I took a look at this today and I can see the issue - this might be fixed by simply changing the homepage element in package.json to "./" as I think this will change how the relative paths are built in index.html.
secondly, the http request processor will need to modify to look for indexOf instead of startsWith in createPostGraphQLHttpRequestHandler.js
I can see if I can put together a PR that will implement this.
Thanks for looking into this @angelosarto. One comment on your proposal: looking for indexOf is quite dangerous - then it could appear anywhere in the query string e.g. /unrelated/path/_postgraphql - the check would need to be a lot safer to get merged.
@benjie Ill have to think about it a bit deeper; if its coming in through a proxy we might not know the leading characters. We know it will be {PREFIX} + /_postgraphql/graphiql/ + {ASSET} https://github.com/postgraphql/postgraphql/blob/85e630a9de530b5f141241ab62d2b6974cc6fbd4/src/postgraphql/http/createPostGraphQLHttpRequestHandler.js#L173
Maybe we need to add proxy-prefix as a config parameter then we can still use beginsWith; this will require specifying the proxy prefix when starting postgraphql, but I guess thats what @kkleidal mentioned.
I ran into this too. I am using koa-mount to mount the app under /postgraphql. These paths should be relative to the mount point ideally.
// This is what graphiql looks for:
http://localhost:3000/_postgraphql/graphiql/static/js/main.45934216.js // fail
http://localhost:3000/postgraphql/_postgraphql/graphiql/static/js/main.45934216.js // success
Workaround is to just use standalone graphiql and point its endpointURL to the the postgraphql location.
@kkleidal @vjpr This worked for me by adding the options: graphqlRoute, graphiql, graphiqlRoute
https://www.graphile.org/postgraphile/usage-library/
- graphqlRoute: The endpoint the GraphQL executer will listen on. Defaults to /graphql.
- graphiqlRoute: The endpoint the GraphiQL query interface will listen on (NOTE: GraphiQL will not be enabled unless the graphiql option is set to true). Defaults to /graphiql.
- graphiql: Set this to true to enable the GraphiQL interface.
const pgConfig = {
user: 'user',
host: 'example.com',
database: 'database',
password: 'password',
port: 5432,
}
postgraphile(
pgConfig,
'myschema',
{
'graphqlRoute': '/base/url/path/graphql',
'graphiql': true,
'graphiqlRoute': '/base/url/path/graphiql',
'dynamicJson': true,
appendPlugins: [PostGraphileConnectionFilterPlugin],
}
)
@benjie I think this ticket can be closed since it is solved in version 4
Version in package.json:
"postgraphile": "4.0.0-beta.5",
"postgraphile-plugin-connection-filter": "^1.0.0-beta.6",
Don't the requests to /_postgraphile/* still fail, or did I fix that?
@benjie Still seems broken in 4.0.0-rc.
Its impossible to setup the correct paths inside koa-route.
import koaRewrite from 'koa-rewrite'
const rewriteMiddleware = async (koaApp) => {
koaApp.use(koaRewrite('/_postgraphile/(.*)', '/graphql/_postgraphile/$1'))
koaApp.use(koaRewrite('/postgraphql/graphql', '/graphql/postgraphql/graphql'))
}
There's in-progress code towards this; so pr-wanted removed.
Should not be necessary in 4.1 (except for the watch mode)
Most helpful comment
@benjie Ill have to think about it a bit deeper; if its coming in through a proxy we might not know the leading characters. We know it will be {PREFIX} + /_postgraphql/graphiql/ + {ASSET} https://github.com/postgraphql/postgraphql/blob/85e630a9de530b5f141241ab62d2b6974cc6fbd4/src/postgraphql/http/createPostGraphQLHttpRequestHandler.js#L173
Maybe we need to add proxy-prefix as a config parameter then we can still use beginsWith; this will require specifying the proxy prefix when starting postgraphql, but I guess thats what @kkleidal mentioned.