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

Commit 9df7fa8

Browse files
committed
Refactor TS declaration files
1 parent 0f74f05 commit 9df7fa8

File tree

10 files changed

+88
-21
lines changed

10 files changed

+88
-21
lines changed

.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ overrides:
481481
- files: '**/*.ts'
482482
parser: '@typescript-eslint/parser'
483483
parserOptions:
484-
tsconfigRootDir: './types/'
484+
tsconfigRootDir: './'
485485
project: ['tsconfig.json']
486486
plugins:
487487
- '@typescript-eslint'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
npm-debug.log
88

99
dist
10+
tmp
1011
node_modules
1112
coverage

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
"test:ci": "yarn check --integrity && npm run prettier:check && npm run lint && npm run check && npm run check:ts && npm run testonly:cover && npm run build",
3333
"testonly": "mocha src/**/__tests__/**/*.js",
3434
"testonly:cover": "nyc npm run testonly",
35-
"lint": "eslint src types resources",
35+
"lint": "eslint src resources",
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",
39-
"check:ts": "dtslint types",
39+
"check:ts": "node resources/check-ts.js",
4040
"build": "node resources/build.js",
4141
"changelog": "node resources/gen-changelog.js",
4242
"preversion": ". ./resources/checkgit.sh",

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+
}
File renamed without changes.

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.
@@ -173,7 +169,11 @@ export interface RequestInfo {
173169
context?: unknown;
174170
}
175171

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

178178
export interface GraphQLParams {
179179
query: string | null;
@@ -182,8 +182,4 @@ export interface GraphQLParams {
182182
raw: boolean;
183183
}
184184

185-
/**
186-
* Middleware for express; takes an options object or function as input to
187-
* configure behavior, and returns an express middleware.
188-
*/
189-
export function graphqlHTTP(options: Options): Middleware;
185+
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;
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
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,
810
"strictFunctionTypes": true,
11+
"baseUrl": "./",
912
"noEmit": true,
10-
"baseUrl": ".",
13+
"forceConsistentCasingInFileNames": true,
1114
"paths": { "express-graphql": ["."] }
1215
}
1316
}

0 commit comments

Comments
 (0)