Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 4140325

Browse files
danielreardenIvanGoncharov
authored andcommitted
Add missing parameter types
1 parent b2f7297 commit 4140325

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/__tests__/http-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import {
1919
GraphQLNonNull,
2020
GraphQLString,
2121
GraphQLError,
22+
ValidationContext,
2223
BREAK,
2324
Source,
2425
validate,
2526
execute,
2627
parse,
28+
type ASTVisitor,
2729
} from 'graphql';
2830

2931
import { graphqlHTTP } from '../index';
@@ -1962,7 +1964,9 @@ function runTests(server) {
19621964
});
19631965

19641966
describe('Custom validation rules', () => {
1965-
const AlwaysInvalidRule = function (context) {
1967+
const AlwaysInvalidRule = function (
1968+
context: ValidationContext,
1969+
): ASTVisitor {
19661970
return {
19671971
enter() {
19681972
context.reportError(

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export function graphqlHTTP(options: Options): Middleware {
194194
return async function graphqlMiddleware(
195195
request: $Request,
196196
response: $Response,
197-
) {
197+
): Promise<void> {
198198
// Higher scoped variables are referred to at various stages in the asynchronous state machine below.
199199
let params: GraphQLParams;
200200
let showGraphiQL = false;

src/parseBody.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow strict
22

33
import { type IncomingMessage } from 'http';
4-
import zlib from 'zlib';
4+
import zlib, { type Inflate, type Gunzip } from 'zlib';
55
import querystring from 'querystring';
66

77
import getBody from 'raw-body';
@@ -76,7 +76,11 @@ export async function parseBody(
7676
const jsonObjRegex = /^[ \t\n\r]*\{/;
7777

7878
// Read and parse a request body.
79-
async function readBody(req, typeInfo) {
79+
async function readBody(
80+
req: $Request,
81+
// TODO: Import the appropriate TS type and use it here instead
82+
typeInfo: {| type: string, parameters: { [param: string]: string, ... } |},
83+
): Promise<string> {
8084
const charset = (typeInfo.parameters.charset ?? 'utf-8').toLowerCase();
8185

8286
// Assert charset encoding per JSON RFC 7159 sec 8.1
@@ -105,7 +109,10 @@ async function readBody(req, typeInfo) {
105109
}
106110

107111
// Return a decompressed stream, given an encoding.
108-
function decompressed(req, encoding) {
112+
function decompressed(
113+
req: $Request,
114+
encoding: string,
115+
): $Request | Inflate | Gunzip {
109116
switch (encoding) {
110117
case 'identity':
111118
return req;

src/renderGraphiQL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type GraphiQLOptions = {|
1919
|};
2020

2121
// Ensures string values are safe to be used within a <script> tag.
22-
function safeSerialize(data) {
22+
function safeSerialize(data: ?string): string {
2323
return data != null
2424
? JSON.stringify(data).replace(/\//g, '\\/')
2525
: 'undefined';

0 commit comments

Comments
 (0)