diff --git a/package.json b/package.json index efc7e4f635..1ee2e6478f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" }, diff --git a/src/interfaces.ts b/src/interfaces.ts index be752bd1dd..f0313c1e17 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -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'); /** @@ -95,13 +96,13 @@ export interface PostGraphileOptions { ) => Array); // An array of [Graphile Build](/graphile-build/plugins/) plugins to load // after the default plugins. - appendPlugins?: Array<(builder: mixed) => {}>; + appendPlugins?: Array; // 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; // 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; // 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; @@ -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 | Array | string | void; + [s: string]: ReadonlyArray | ReadonlyArray | string | void; message: string; - locations: Array | void; - path: Array | void; -} - -export interface GraphQLErrorLocation { - line: number; - column: number; + locations: ReadonlyArray | void; + path: ReadonlyArray | void; } export type GraphQLErrorExtended = GraphQLError & { diff --git a/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts b/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts index 51067369d3..951e40427e 100644 --- a/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts +++ b/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts @@ -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; @@ -266,7 +266,7 @@ export default function createPostGraphileHttpRequestHandler( const SHA1_BASE64_LENGTH = 28; interface CacheEntry { queryDocumentAst: DocumentNode; - validationErrors: Array; + validationErrors: ReadonlyArray; length: number; } const queryCache = LRU({ @@ -280,7 +280,7 @@ export default function createPostGraphileHttpRequestHandler( queryString: string, ): { queryDocumentAst: DocumentNode; - validationErrors: Array; + validationErrors: ReadonlyArray; } => { if (gqlSchema !== lastGqlSchema) { queryCache.reset(); @@ -642,7 +642,7 @@ export default function createPostGraphileHttpRequestHandler( `Operation name must be a string, not '${typeof params.operationName}'.`, ); - let validationErrors: Array; + let validationErrors: ReadonlyArray; ({ queryDocumentAst, validationErrors } = parseQuery(gqlSchema, params.query)); if (validationErrors.length === 0) { diff --git a/src/postgraphile/postgraphile.ts b/src/postgraphile/postgraphile.ts index 491da72263..389cda0793 100644 --- a/src/postgraphile/postgraphile.ts +++ b/src/postgraphile/postgraphile.ts @@ -62,7 +62,7 @@ export function getPostgraphileSchemaBuilder( async function createGqlSchema(): Promise { 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); diff --git a/src/postgraphile/withPostGraphileContext.ts b/src/postgraphile/withPostGraphileContext.ts index 4ab3ec8cf1..8b8206c332 100644 --- a/src/postgraphile/withPostGraphileContext.ts +++ b/src/postgraphile/withPostGraphileContext.ts @@ -110,7 +110,7 @@ const withDefaultPostGraphileContext: WithPostGraphileContextFn = async ( // add settings for keys we've already seen. const seenKeys: Array = []; - const sqlSettings: Array = []; + const sqlSettings: Array = []; for (let i = localSettings.length - 1; i >= 0; i--) { const [key, value] = localSettings[i]; if (seenKeys.indexOf(key) < 0) { @@ -118,7 +118,9 @@ const withDefaultPostGraphileContext: WithPostGraphileContextFn = async ( // 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)`, + ); } } diff --git a/tsconfig.json b/tsconfig.json index 482aa57b94..4905a02f24 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,11 @@ "strictNullChecks": true, "noFallthroughCasesInSwitch": true, "noUnusedParameters": true, - "noUnusedLocals": true + "noUnusedLocals": true, + "lib": [ + "es2017", + "esnext.asynciterable" + ] }, "exclude": [ "index.js", diff --git a/typings/pg-sql2.d.ts b/typings/pg-sql2.d.ts deleted file mode 100644 index dea0a06f09..0000000000 --- a/typings/pg-sql2.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare module 'pg-sql2' { - import { QueryConfig } from 'pg' - - interface SQLNode {} - type SQLQuery = Array - - export function compile(query: SQLQuery): QueryConfig - export function query(strings: TemplateStringsArray, ...values: Array): SQLQuery - export function value(val: any): SQLNode - export function join(items: Array, separator?: string): SQLQuery -} diff --git a/typings/postgraphile-core.d.ts b/typings/postgraphile-core.d.ts deleted file mode 100644 index 90739fc353..0000000000 --- a/typings/postgraphile-core.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -declare module 'postgraphile-core' { - import { Pool, Client, ClientConfig } from 'pg' - import { GraphQLSchema } from 'graphql' - export function createPostGraphileSchema ( - clientOrConfig: Pool | Client | ClientConfig | string, - schemaOrCatalog: string | Array, - options?: { - classicIds?: boolean, - dynamicJson?: boolean, - jwtSecret?: string, - jwtPgTypeIdentifier?: string, - disableDefaultMutations?: boolean, - }, - ): Promise - - export function watchPostGraphileSchema ( - clientOrConfig: Pool | Client | ClientConfig | string, - schemaOrCatalog: string | Array, - options: { - classicIds?: boolean, - dynamicJson?: boolean, - jwtSecret?: string, - jwtPgTypeIdentifier?: string, - disableDefaultMutations?: boolean, - }, - onSchema: (schema: GraphQLSchema) => void, - ): Promise<() => {}> -} diff --git a/yarn.lock b/yarn.lock index 9a7ecc3d4b..f09869508f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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: @@ -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: @@ -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"