From 7834cedf60f141704f606c41c9fdcbcb802b4860 Mon Sep 17 00:00:00 2001 From: Daniel Rearden Date: Wed, 10 Jun 2020 15:01:25 -0400 Subject: [PATCH] Add missing parameter types --- src/__tests__/http-test.js | 5 ++++- src/index.js | 2 +- src/parseBody.js | 13 ++++++++++--- src/renderGraphiQL.js | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/__tests__/http-test.js b/src/__tests__/http-test.js index bab24e94..b952b1a6 100644 --- a/src/__tests__/http-test.js +++ b/src/__tests__/http-test.js @@ -19,6 +19,7 @@ import { GraphQLNonNull, GraphQLString, GraphQLError, + ValidationContext, BREAK, Source, validate, @@ -1962,7 +1963,9 @@ function runTests(server) { }); describe('Custom validation rules', () => { - const AlwaysInvalidRule = function (context) { + const AlwaysInvalidRule = function ( + context: ValidationContext, + ): { [key: string]: mixed, ... } { return { enter() { context.reportError( diff --git a/src/index.js b/src/index.js index d5adbd66..2c39d170 100644 --- a/src/index.js +++ b/src/index.js @@ -194,7 +194,7 @@ export function graphqlHTTP(options: Options): Middleware { return async function graphqlMiddleware( request: $Request, response: $Response, - ) { + ): Promise { // Higher scoped variables are referred to at various stages in the asynchronous state machine below. let params: GraphQLParams; let showGraphiQL = false; diff --git a/src/parseBody.js b/src/parseBody.js index 812ff276..8e244ee5 100644 --- a/src/parseBody.js +++ b/src/parseBody.js @@ -1,7 +1,7 @@ // @flow strict import { type IncomingMessage } from 'http'; -import zlib from 'zlib'; +import zlib, { type Inflate, type Gunzip } from 'zlib'; import querystring from 'querystring'; import getBody from 'raw-body'; @@ -76,7 +76,11 @@ export async function parseBody( const jsonObjRegex = /^[ \t\n\r]*\{/; // Read and parse a request body. -async function readBody(req, typeInfo) { +async function readBody( + req: $Request, + // TODO: Import the appropriate TS type and use it here instead + typeInfo: {| type: string, parameters: { [param: string]: string, ... } |}, +): Promise { const charset = (typeInfo.parameters.charset ?? 'utf-8').toLowerCase(); // Assert charset encoding per JSON RFC 7159 sec 8.1 @@ -105,7 +109,10 @@ async function readBody(req, typeInfo) { } // Return a decompressed stream, given an encoding. -function decompressed(req, encoding) { +function decompressed( + req: $Request, + encoding: string, +): $Request | Inflate | Gunzip { switch (encoding) { case 'identity': return req; diff --git a/src/renderGraphiQL.js b/src/renderGraphiQL.js index 6512d6ca..aa16a9ac 100644 --- a/src/renderGraphiQL.js +++ b/src/renderGraphiQL.js @@ -19,9 +19,9 @@ export type GraphiQLOptions = {| |}; // Ensures string values are safe to be used within a