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

Warn user when they pass undefined schema in library mode #951

Closed
1 of 3 tasks
marshall007 opened this issue Jan 5, 2019 · 4 comments
Closed
1 of 3 tasks

Warn user when they pass undefined schema in library mode #951

marshall007 opened this issue Jan 5, 2019 · 4 comments

Comments

@marshall007
Copy link
Contributor

I'm submitting a ...

  • bug report
  • feature request
  • question

PostGraphile version: v4.1.0

Steps to reproduce:

import postgraphile from 'postgraphile';
import { createServer } from 'http';

const {
  PORT,
  POSTGRES_DB,
  POSTGRES_PASSWORD,
  POSTGRES_USER,
  POSTGRES_HOST,
  POSTGRES_SCHEMA,
} = process.env;

const POSTGRES_CONNECTION_STRING = `postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}`;

const app = createServer(
  postgraphile(POSTGRES_CONNECTION_STRING, POSTGRES_SCHEMA, {
    graphiql: true,
    enhanceGraphiql: true,
  }),
);

const port = PORT || 5000;

app.listen(port, (err?: Error) => {
  if (err != null) console.error(err);
  console.log(`Listening on http://localhost:${port}`);
});

Current behavior:

When using as a library (as demonstrated above), if the second argument to postgraphile is undefined, the server appears to start successfully and responds to requests at /graphql, but does not serve the UI at /graphiql.

In this case, it took me a while to realize I was not setting the POSTGRES_SCHEMA environment variable and that it was causing the problem.

Expected behavior:

Invalid configuration should immediately throw and prevent the server from starting all together.

@benjie
Copy link
Member

benjie commented Jan 5, 2019

Could you expand on “does not serve the UI”? Do you get an error?

PostGraphile will fall back to the “public” schema if no schema is passed, this is the desired behaviour. So you should see a (empty schema’d?) GraphiQL when you visit. Seeing no GraphiQL at all is definitely unexpected, hence the request to clarify. Feel free to attach screenshot.

@marshall007
Copy link
Contributor Author

@benjie right, the GraphiQL UI is not served up at all in this case. Visiting /graphiql results in the standard Node HTTP 404 error:

Cannot GET /graphiql

I would also argue that while using the public schema is desirable default behavior via other configuration mechanisms, library usage where schema is the second parameter should probably at least warn, if not error, when the second parameter is undefined. In this scenario, it's much more likely that the user accidentally passed an undefined value (as I did), not undefined explicitly.

@benjie
Copy link
Member

benjie commented Jan 7, 2019

I think I agree with you, IFF the third argument is specified. Definitely an error at least.

@benjie benjie changed the title Server silently fails to start properly with invalid arguments Warn user when they pass undefined schema in library mode Jan 9, 2019
marshall007 added a commit to mridevteam/postgraphile that referenced this issue Jan 11, 2019
marshall007 added a commit to mridevteam/postgraphile that referenced this issue Jan 11, 2019
@benjie
Copy link
Member

benjie commented Jan 24, 2019

postgraphile@next (4.3.1) is now out; please see if this is solved and report back 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants