0

I have a database in pgadmin name "mydatabase" and the tablename is "mytable". It runs in http://127.0.0.1:33859/browser/. I was trying to use postgraphile to connect with it. Here is the code

const express = require("express");
const { postgraphile } = require("postgraphile");

const app = express();

app.use(postgraphile("postgres://postgres:postgres@localhost:33859/mydatabase -s public"));

app.listen(3000);

My superuser username is "postgres" and password is "postgres". The database is owned by a user named "test" with password "1234". After running the script with node, there is no error at the terminal. When I hit the port 3000, it shows Cannot GET /. Any help on this?

Proteeti Prova
  • 1,079
  • 4
  • 25
  • 49

1 Answers1

1

Because the PostGraphile middleware is expected to be mounted along with the rest of your Node.js app, it doesn't take over the root URL and instead makes the GraphQL endpoint available at /graphql by default. To change this there are the graphqlRoute and graphiqlRoute options documented in the Library Usage page.

Here's some good options to get you started:

const isDev = process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "staging";    
const DB = "postgres://postgres:postgres@localhost:33859/mydatabase -s public";
const SCHEMA = "public";

app.use(postgraphile(DB, SCHEMA, {
  // Enable the GraphiQL IDE in development
  graphiql: isDev,
  // Add some enhancements (headers, formatting, etc)
  enhanceGraphiql: isDev,

  // Makes GraphiQL available at http://localhost:3000/ rather than /graphiql
  graphiqlRoute: '/',

  // Watch DB for changes
  watchPg: isDev,

  // Use JSON objects rather than strings
  dynamicJson: true,

  // Debugging
  showErrorStack: isDev,
  extendedErrors:
    isDev
      ? [
          "errcode",
          "severity",
          "detail",
          "hint",
          "positon",
          "internalPosition",
          "internalQuery",
          "where",
          "schema",
          "table",
          "column",
          "dataType",
          "constraint",
          "file",
          "line",
          "routine",
        ]
      : ["errcode"],

    // For use with e.g. apollo-link-batch-http
    enableQueryBatching: true,

}));

You might find the bootstrap-react-apollo installPostGraphile.js file a good place to get started.

Benjie
  • 7,701
  • 5
  • 29
  • 44