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

fix(errors): tweaks to errors/logs/etc #56

Merged
merged 6 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/graphile-build-pg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"homepage": "https://github.com/graphile/graphile-build#readme",
"dependencies": {
"babel-runtime": ">=6 <7",
"chalk": "^2.1.0",
"debug": ">=2 <3",
"graphile-build": "^0.1.0-alpha.18",
"graphql-iso-date": "^3.2.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/graphile-build-pg/src/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ class QueryBuilder {
// no need to change anything
}
} else if (offset > 0) {
// eslint-disable-next-line
debugger
throw new Error("Cannot combine 'last' and 'offset'");
} else {
if (this.compiledData.orderBy.length > 0) {
Expand Down
21 changes: 18 additions & 3 deletions packages/graphile-build-pg/src/plugins/PgIntrospectionPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import withPgClient from "../withPgClient";
import { readFile as rawReadFile } from "fs";
import pg from "pg";
import debugFactory from "debug";
import chalk from "chalk";
const debug = debugFactory("graphile-build-pg");
const INTROSPECTION_PATH = `${__dirname}/../../res/introspection-query.sql`;
const WATCH_FIXTURES_PATH = `${__dirname}/../../res/watch-fixtures.sql`;
Expand Down Expand Up @@ -239,11 +240,25 @@ export default (async function PgIntrospectionPlugin(
await pgClient.query(sql);
} catch (error) {
/* eslint-disable no-console */
console.warn("Failed to setup watch fixtures in Postgres database");
console.warn(
"This is likely because your Postgres user is not a superuser. If the fixtures already exist, the watch functionality may still work."
`${chalk.bold.yellow(
"Failed to setup watch fixtures in Postgres database"
)} ️️⚠️`
);
console.warn(error);
console.warn(
chalk.yellow(
"This is likely because your Postgres user is not a superuser. If the"
)
);
console.warn(
chalk.yellow(
"fixtures already exist, the watch functionality may still work."
)
);
console.warn(
chalk.yellow("Enable DEBUG='graphile-build-pg' to see the error")
);
debug(error);
/* eslint-enable no-console */
await pgClient.query("rollback");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Plugin } from "graphile-build";
import makeProcField from "./makeProcField";
import debugFactory from "debug";
import chalk from "chalk";

const debugWarn = debugFactory("graphile-build-pg:warn");

Expand Down Expand Up @@ -71,8 +72,10 @@ export default (function PgQueryProceduresPlugin(builder) {
} catch (e) {
// eslint-disable-next-line no-console
console.warn(
`Failed to add function '${proc.namespace
.name}.${proc.name}'; run with 'DEBUG="graphile-build-pg:warn"' to view the error`
chalk.bold.yellow(
`Failed to add function '${proc.namespace
.name}.${proc.name}'; run with 'DEBUG="graphile-build-pg:warn"' to view the error`
)
);
debugWarn(e);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/graphile-build/src/makeNewBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function ensureArray<T>(val: void | Array<T> | T): void | Array<T> {
let ensureName = fn => {};
if (["development", "test"].indexOf(process.env.NODE_ENV) >= 0) {
ensureName = fn => {
if (isDev && !fn.displayName && !fn.name) {
if (isDev && !fn.displayName && !fn.name && debug.enabled) {
// eslint-disable-next-line no-console
console.trace(
"WARNING: you've added a function with no name as an argDataGenerator, doing so may make debugging more challenging"
Expand Down Expand Up @@ -187,7 +187,7 @@ export default function makeNewBuild(builder: SchemaBuilder): Build {
console.warn(
`No scope was provided to new ${getNameFromType(
Type
)}[name=${spec.name}], please check usage of 'newWithHooks'`
)}[name=${spec.name}], it's highly recommended that you add a scope so other hooks can easily reference your object - please check usage of 'newWithHooks'. To mute this message, just pass an empty object.`
);
}
if (!Type) {
Expand Down
8 changes: 8 additions & 0 deletions packages/postgraphile-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ const getPostGraphQLBuilder = async (
} = options;
if (replaceAllPlugins) {
ensureValidPlugins("replaceAllPlugins", replaceAllPlugins);
if (
(prependPlugins && prependPlugins.length) ||
(appendPlugins && appendPlugins.length)
) {
throw new Error(
"When using 'replaceAllPlugins' you must not specify 'appendPlugins'/'prependPlugins'"
);
}
}
ensureValidPlugins("prependPlugins", prependPlugins);
ensureValidPlugins("appendPlugins", appendPlugins);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^2.0.0:
chalk@^2.0.0, chalk@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.1.0.tgz#ac5becf14fa21b99c6c92ca7a7d7cfd5b17e743e"
dependencies:
Expand Down