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

Commit 227093d

Browse files
committed
Refactor TS declaration files
1 parent 6a1e317 commit 227093d

File tree

7 files changed

+83
-18
lines changed

7 files changed

+83
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"test:ci": "npm ci && npm run prettier:check && npm run lint && npm run check && npm run testonly:cover && npm run build && npm run check:integrations",
3333
"testonly": "mocha src/**/__tests__/**/*.js",
3434
"testonly:cover": "nyc npm run testonly",
35-
"lint": "eslint src types resources integrationTests",
35+
"lint": "eslint src resources integrationTests",
3636
"prettier": "prettier --ignore-path .gitignore --write --list-different '**/*.{js,ts,md,json,yml}'",
3737
"prettier:check": "prettier --ignore-path .gitignore --check '**/*.{js,ts,md,json,yml}'",
3838
"check": "flow check",

resources/build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ if (require.main === module) {
2525

2626
const cjs = babelBuild(srcPath, { envName: 'cjs' });
2727
fs.writeFileSync(destPath, cjs);
28+
} else if (filepath.endsWith('d.ts')) {
29+
fs.copyFileSync(srcPath, destPath);
2830
}
2931
}
3032

31-
fs.copyFileSync('./types/index.d.ts', './dist/index.d.ts');
3233
fs.copyFileSync('./LICENSE', './dist/LICENSE');
3334
fs.copyFileSync('./README.md', './dist/README.md');
3435

resources/check-ts.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @noflow
2+
3+
'use strict';
4+
5+
const fs = require('fs');
6+
const path = require('path');
7+
8+
const { exec, rmdirRecursive, readdirRecursive } = require('./utils');
9+
10+
rmdirRecursive('./tmp');
11+
fs.mkdirSync('./tmp');
12+
fs.mkdirSync('./tmp/__tests__');
13+
14+
const srcFiles = readdirRecursive('./src');
15+
for (const filepath of srcFiles) {
16+
const srcPath = path.join('./src', filepath);
17+
const destPath = path.join('./tmp', filepath);
18+
19+
if (filepath.endsWith('.ts')) {
20+
fs.copyFileSync(srcPath, destPath);
21+
}
22+
}
23+
24+
fs.copyFileSync('tsconfig.json', path.join('./tmp', 'tsconfig.json'));
25+
26+
try {
27+
exec('dtslint tmp', { stdio: 'inherit' });
28+
} finally {
29+
rmdirRecursive('./tmp');
30+
}

types/index.d.ts renamed to src/index.d.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ import {
1616
GraphQLTypeResolver,
1717
} from 'graphql';
1818

19+
import { GraphiQLOptions } from './renderGraphiQL';
20+
1921
export {};
2022

2123
type Request = IncomingMessage;
24+
2225
type Response = ServerResponse & { json?: (data: unknown) => void };
2326

27+
type Middleware = (request: Request, response: Response) => Promise<void>;
28+
2429
/**
2530
* Used to configure the graphqlHTTP middleware by providing a schema
2631
* and other configuration options.
@@ -37,15 +42,6 @@ export type Options =
3742
| OptionsResult;
3843
type OptionsResult = OptionsData | Promise<OptionsData>;
3944

40-
export interface GraphiQLOptions {
41-
/**
42-
* An optional GraphQL string to use when no query is provided and no stored
43-
* query exists from a previous session. If undefined is provided, GraphiQL
44-
* will use its own default query.
45-
*/
46-
defaultQuery?: string;
47-
}
48-
4945
export interface OptionsData {
5046
/**
5147
* A GraphQL schema from graphql-js.
@@ -175,7 +171,11 @@ export interface RequestInfo {
175171
context?: unknown;
176172
}
177173

178-
type Middleware = (request: Request, response: Response) => Promise<void>;
174+
/**
175+
* Middleware for express; takes an options object or function as input to
176+
* configure behavior, and returns an express middleware.
177+
*/
178+
export function graphqlHTTP(options: Options): Middleware;
179179

180180
export interface GraphQLParams {
181181
query: string | null;
@@ -184,8 +184,4 @@ export interface GraphQLParams {
184184
raw: boolean;
185185
}
186186

187-
/**
188-
* Middleware for express; takes an options object or function as input to
189-
* configure behavior, and returns an express middleware.
190-
*/
191-
export function graphqlHTTP(options: Options): Middleware;
187+
export function getGraphQLParams(request: Request): Promise<GraphQLParams>;

src/parseBody.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { IncomingMessage } from 'http';
2+
3+
export {};
4+
5+
type Request = IncomingMessage & { body?: unknown };
6+
7+
export function parseBody(req: Request): Promise<{ [param: string]: unknown }>;

src/renderGraphiQL.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ExecutionResult } from 'graphql';
2+
3+
export interface GraphiQLData {
4+
query?: string | null;
5+
variables?: { readonly [name: string]: unknown } | null;
6+
operationName?: string | null;
7+
result?: ExecutionResult;
8+
}
9+
10+
export interface GraphiQLOptions {
11+
/**
12+
* An optional GraphQL string to use when no query is provided and no stored
13+
* query exists from a previous session. If undefined is provided, GraphiQL
14+
* will use its own default query.
15+
*/
16+
defaultQuery?: string;
17+
}
18+
19+
/**
20+
* When express-graphql receives a request which does not Accept JSON, but does
21+
* Accept HTML, it may present GraphiQL, the in-browser GraphQL explorer IDE.
22+
*
23+
* When shown, it will be pre-populated with the result of having executed the
24+
* requested query.
25+
*/
26+
export function renderGraphiQL(
27+
data: GraphiQLData,
28+
options?: GraphiQLOptions,
29+
): string;

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4-
"lib": ["es6", "esnext.asynciterable"],
4+
"target": "es2018",
5+
"moduleResolution": "node",
6+
"lib": ["es2018", "esnext.asynciterable"],
57
"noImplicitAny": true,
68
"noImplicitThis": true,
79
"strictNullChecks": true,

0 commit comments

Comments
 (0)