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

Commit

Permalink
Add missing parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrearden committed Jun 11, 2020
1 parent b2f7297 commit 15ae54e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/__tests__/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import {
GraphQLNonNull,
GraphQLString,
GraphQLError,
ValidationContext,
BREAK,
Source,
validate,
execute,
parse,
type ASTVisitor,
} from 'graphql';

import { graphqlHTTP } from '../index';
Expand Down Expand Up @@ -1962,7 +1964,9 @@ function runTests(server) {
});

describe('Custom validation rules', () => {
const AlwaysInvalidRule = function (context) {
const AlwaysInvalidRule = function (
context: ValidationContext,
): ASTVisitor {
return {
enter() {
context.reportError(
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export function graphqlHTTP(options: Options): Middleware {
return async function graphqlMiddleware(
request: $Request,
response: $Response,
) {
): Promise<void> {
// Higher scoped variables are referred to at various stages in the asynchronous state machine below.
let params: GraphQLParams;
let showGraphiQL = false;
Expand Down
13 changes: 10 additions & 3 deletions src/parseBody.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<string> {
const charset = (typeInfo.parameters.charset ?? 'utf-8').toLowerCase();

// Assert charset encoding per JSON RFC 7159 sec 8.1
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/renderGraphiQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type GraphiQLOptions = {|
|};

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

0 comments on commit 15ae54e

Please sign in to comment.