Skip to content

Commit

Permalink
feat(deps): upgrade pg-sql2 and postgraphile-core (#839)
Browse files Browse the repository at this point in the history
- Better TypeScript support
- Many fixes, including:
  - enable update/delete mutations for tables lacking primary keys
  - fix bug in introspection query that could in some very rare circumstances cause tables or functions to be omitted from the generated schema
  - fixing a template string that accidentally had straight quotes (thanks @mathroc)
  - more useful error message when using legacy graphql versions with graphile-utils
  - fix bug in regex for validating long aliases
- More information in some places for plugins to use
- Better errors in a few places
- `hstore` support
- `inet` support thanks to @syndesis
- `graphile-utils` enhancements
  - including enum support thanks to @bradleyayers
  • Loading branch information
benjie authored Aug 22, 2018
1 parent 7d605a5 commit 4507b3d
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 85 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"prepack": "./scripts/build"
},
"dependencies": {
"@types/graphql": "^0.8.2",
"@types/graphql": "0.13.4",
"@types/jsonwebtoken": "<7.2.1",
"@types/koa": "2.0.44",
"@types/pg": "^7.4.10",
Expand All @@ -55,8 +55,8 @@
"parseurl": "^1.3.1",
"pg": ">=6.1.0 <8",
"pg-connection-string": "^0.1.3",
"pg-sql2": "^2.1.0",
"postgraphile-core": "4.0.0-rc.5",
"pg-sql2": "2.2.1",
"postgraphile-core": "4.0.0-rc.7",
"send": "^0.16.1",
"tslib": "^1.5.0"
},
Expand Down
20 changes: 8 additions & 12 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* tslint:disable:no-any */
import { EventEmitter } from 'events';
import { GraphQLError, GraphQLSchema } from 'graphql';
import { GraphQLError, GraphQLSchema, SourceLocation } from 'graphql';
import { IncomingMessage, ServerResponse } from 'http';
import { PluginHookFn } from './postgraphile/pluginHook';
import { Pool } from 'pg';
import { Plugin } from 'postgraphile-core';
import jwt = require('jsonwebtoken');

/**
Expand Down Expand Up @@ -95,13 +96,13 @@ export interface PostGraphileOptions {
) => Array<GraphQLErrorExtended>);
// An array of [Graphile Build](/graphile-build/plugins/) plugins to load
// after the default plugins.
appendPlugins?: Array<(builder: mixed) => {}>;
appendPlugins?: Array<Plugin>;
// An array of [Graphile Build](/graphile-build/plugins/) plugins to load
// before the default plugins (you probably don't want this).
prependPlugins?: Array<(builder: mixed) => {}>;
prependPlugins?: Array<Plugin>;
// The full array of [Graphile Build](/graphile-build/plugins/) plugins to
// use for schema generation (you almost definitely don't want this!).
replaceAllPlugins?: Array<(builder: mixed) => {}>;
replaceAllPlugins?: Array<Plugin>;
// A file path string. Reads cached values from local cache file to improve
// startup time (you may want to do this in production).
readCache?: string;
Expand Down Expand Up @@ -214,15 +215,10 @@ export interface PostGraphileOptions {

export interface GraphQLFormattedErrorExtended {
// This is ugly, really I just want `string | void` but apparently TypeScript doesn't support that.
[s: string]: Array<GraphQLErrorLocation> | Array<string | number> | string | void;
[s: string]: ReadonlyArray<SourceLocation> | ReadonlyArray<string | number> | string | void;
message: string;
locations: Array<GraphQLErrorLocation> | void;
path: Array<string | number> | void;
}

export interface GraphQLErrorLocation {
line: number;
column: number;
locations: ReadonlyArray<SourceLocation> | void;
path: ReadonlyArray<string | number> | void;
}

export type GraphQLErrorExtended = GraphQLError & {
Expand Down
8 changes: 4 additions & 4 deletions src/postgraphile/http/createPostGraphileHttpRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default function createPostGraphileHttpRequestHandler(
// If the user wants to see the error’s stack, let’s add it to the
// formatted error.
if (options.showErrorStack)
formattedError.stack =
(formattedError as object)['stack'] =
error.stack != null && options.showErrorStack === 'json'
? error.stack.split('\n')
: error.stack;
Expand Down Expand Up @@ -266,7 +266,7 @@ export default function createPostGraphileHttpRequestHandler(
const SHA1_BASE64_LENGTH = 28;
interface CacheEntry {
queryDocumentAst: DocumentNode;
validationErrors: Array<GraphQLError>;
validationErrors: ReadonlyArray<GraphQLError>;
length: number;
}
const queryCache = LRU({
Expand All @@ -280,7 +280,7 @@ export default function createPostGraphileHttpRequestHandler(
queryString: string,
): {
queryDocumentAst: DocumentNode;
validationErrors: Array<GraphQLError>;
validationErrors: ReadonlyArray<GraphQLError>;
} => {
if (gqlSchema !== lastGqlSchema) {
queryCache.reset();
Expand Down Expand Up @@ -642,7 +642,7 @@ export default function createPostGraphileHttpRequestHandler(
`Operation name must be a string, not '${typeof params.operationName}'.`,
);

let validationErrors: Array<GraphQLError>;
let validationErrors: ReadonlyArray<GraphQLError>;
({ queryDocumentAst, validationErrors } = parseQuery(gqlSchema, params.query));

if (validationErrors.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/postgraphile/postgraphile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function getPostgraphileSchemaBuilder(
async function createGqlSchema(): Promise<GraphQLSchema> {
try {
if (options.watchPg) {
await watchPostGraphileSchema(pgPool, pgSchemas, options, (newSchema: GraphQLSchema) => {
await watchPostGraphileSchema(pgPool, pgSchemas, options, newSchema => {
gqlSchema = newSchema;
_emitter.emit('schemas:changed');
exportGqlSchema(gqlSchema);
Expand Down
6 changes: 4 additions & 2 deletions src/postgraphile/withPostGraphileContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ const withDefaultPostGraphileContext: WithPostGraphileContextFn = async (
// add settings for keys we've already seen.
const seenKeys: Array<string> = [];

const sqlSettings: Array<sql.SQLNode> = [];
const sqlSettings: Array<sql.SQLQuery> = [];
for (let i = localSettings.length - 1; i >= 0; i--) {
const [key, value] = localSettings[i];
if (seenKeys.indexOf(key) < 0) {
seenKeys.push(key);
// Make sure that the third config is always `true` so that we are only
// ever setting variables on the transaction.
// Also, we're using `unshift` to undo the reverse-looping we're doing
sqlSettings.unshift(sql.query`set_config(${sql.value(key)}, ${sql.value(value)}, true)`);
sqlSettings.unshift(
sql.fragment`set_config(${sql.value(key)}, ${sql.value(value)}, true)`,
);
}
}

Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
"strictNullChecks": true,
"noFallthroughCasesInSwitch": true,
"noUnusedParameters": true,
"noUnusedLocals": true
"noUnusedLocals": true,
"lib": [
"es2017",
"esnext.asynciterable"
]
},
"exclude": [
"index.js",
Expand Down
11 changes: 0 additions & 11 deletions typings/pg-sql2.d.ts

This file was deleted.

28 changes: 0 additions & 28 deletions typings/postgraphile-core.d.ts

This file was deleted.

50 changes: 27 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
dependencies:
"@types/node" "*"

"@types/graphql@^0.8.2":
version "0.8.6"
resolved "https://registry.yarnpkg.com/@types/graphql/-/graphql-0.8.6.tgz#b34fb880493ba835b0c067024ee70130d6f9bb68"
"@types/graphql@0.13.4":
version "0.13.4"
resolved "https://registry.yarnpkg.com/@types/graphql/-/graphql-0.13.4.tgz#55ae9c29f0fd6b85ee536f5c72b4769d5c5e06b1"

"@types/http-assert@*":
version "1.3.0"
Expand Down Expand Up @@ -3360,26 +3360,27 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

graphile-build-pg@4.0.0-rc.5:
version "4.0.0-rc.5"
resolved "https://registry.yarnpkg.com/graphile-build-pg/-/graphile-build-pg-4.0.0-rc.5.tgz#ddb2ee53ba228cd1b102ca1907cba0c520794388"
graphile-build-pg@4.0.0-rc.6:
version "4.0.0-rc.6"
resolved "https://registry.yarnpkg.com/graphile-build-pg/-/graphile-build-pg-4.0.0-rc.6.tgz#57e138921d4d4c63d07c713656124e846b5ae476"
dependencies:
chalk "^2.1.0"
debug ">=2 <3"
graphile-build "4.0.0-rc.5"
graphile-build "4.0.0-rc.6"
graphql-iso-date "^3.2.0"
jsonwebtoken "^8.1.1"
lodash ">=4 <5"
lru-cache ">=4 <5"
pg-sql2 "2.1.0"
pg-sql2 "2.2.1"
postgres-interval "1.1.1"

graphile-build@4.0.0-rc.5:
version "4.0.0-rc.5"
resolved "https://registry.yarnpkg.com/graphile-build/-/graphile-build-4.0.0-rc.5.tgz#d7c5c11d7c732c5dbe293e7262b6ce62c25f7a76"
graphile-build@4.0.0-rc.6:
version "4.0.0-rc.6"
resolved "https://registry.yarnpkg.com/graphile-build/-/graphile-build-4.0.0-rc.6.tgz#24480827311a7376faaf26cf87a64f69124aa9e1"
dependencies:
"@types/graphql" "0.13.4"
debug ">=2 <3"
graphql-parse-resolve-info "4.0.0-rc.4"
graphql-parse-resolve-info "4.0.0-rc.6"
lodash ">=4 <5"
lru-cache ">=4 <5"
pluralize "7.0.0"
Expand Down Expand Up @@ -3451,10 +3452,11 @@ graphql-language-service-utils@^1.2.2:
graphql-config "2.0.1"
graphql-language-service-types "^1.2.2"

graphql-parse-resolve-info@4.0.0-rc.4:
version "4.0.0-rc.4"
resolved "https://registry.yarnpkg.com/graphql-parse-resolve-info/-/graphql-parse-resolve-info-4.0.0-rc.4.tgz#3d719fcd94d2e302e3acbf5b4495415b71c6a1d4"
graphql-parse-resolve-info@4.0.0-rc.6:
version "4.0.0-rc.6"
resolved "https://registry.yarnpkg.com/graphql-parse-resolve-info/-/graphql-parse-resolve-info-4.0.0-rc.6.tgz#60ada2bef94c099375a9cc0c08065626837c0a49"
dependencies:
"@types/graphql" "0.13.4"
debug ">=2 <3"

graphql-request@^1.5.0:
Expand Down Expand Up @@ -5981,10 +5983,11 @@ pg-pool@~2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.3.tgz#c022032c8949f312a4f91fb6409ce04076be3257"

pg-sql2@2.1.0, pg-sql2@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pg-sql2/-/pg-sql2-2.1.0.tgz#f86978278451482099e4f8e8db8b7486ecb67e3f"
pg-sql2@2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/pg-sql2/-/pg-sql2-2.2.1.tgz#a37612e5243887c5135a6849dec1f20b2cf00553"
dependencies:
"@types/pg" "^7.4.10"
debug ">=2 <3"

pg-types@~1.12.1:
Expand Down Expand Up @@ -6343,12 +6346,13 @@ postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.13:
source-map "^0.6.1"
supports-color "^5.4.0"

postgraphile-core@4.0.0-rc.5:
version "4.0.0-rc.5"
resolved "https://registry.yarnpkg.com/postgraphile-core/-/postgraphile-core-4.0.0-rc.5.tgz#95829f3210ccb171d4f771b903d3ffd3952ff2b7"
postgraphile-core@4.0.0-rc.7:
version "4.0.0-rc.7"
resolved "https://registry.yarnpkg.com/postgraphile-core/-/postgraphile-core-4.0.0-rc.7.tgz#6f8724a586b8f413596f6515ae2e3342f7982445"
dependencies:
graphile-build "4.0.0-rc.5"
graphile-build-pg "4.0.0-rc.5"
"@types/graphql" "0.13.4"
graphile-build "4.0.0-rc.6"
graphile-build-pg "4.0.0-rc.6"

postgres-array@~1.0.0:
version "1.0.2"
Expand Down

0 comments on commit 4507b3d

Please sign in to comment.