Поскольку предполагается, что промежуточное программное обеспечение PostGraphile будет смонтировано вместе с остальной частью вашего приложения Node.js, оно не захватывает корневой URL-адрес и вместо этого делает конечную точку GraphQL доступной по умолчанию /graphql
. Чтобы изменить это, есть опции graphqlRoute
и graphiqlRoute
, задокументированные на странице использования библиотеки .
Вот несколько хороших вариантов для начала:
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,
}));
Возможно, файл bootstrap-реагировать-apollo installPostGraphile.js является хорошим местом для начала работы.