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 7834ced
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/__tests__/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
GraphQLNonNull,
GraphQLString,
GraphQLError,
ValidationContext,
BREAK,
Source,
validate,
Expand Down Expand Up @@ -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(
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
4 changes: 2 additions & 2 deletions src/renderGraphiQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export type GraphiQLOptions = {|
|};

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

Expand Down

0 comments on commit 7834ced

Please sign in to comment.