Skip to content

Commit de02686

Browse files
committed
Add typescript
1 parent 8a78808 commit de02686

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ typings/
5959

6060
# next.js build output
6161
.next
62+
63+
# typescript compilation output
64+
dist/

package.json

+17-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,30 @@
22
"name": "apollo-server-integration-testing",
33
"version": "1.0.0",
44
"description": "Test helper for writing apollo-server integration tests",
5-
"main": "src/index.js",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
67
"repository": "https://github.com/zapier/apollo-server-integration-testing.git",
78
"author": "Vitor Balocco <[email protected]>",
89
"license": "MIT",
910
"private": false,
11+
"scripts": {
12+
"compile": "tsc --clean",
13+
"prepublish": "yarn compile"
14+
},
1015
"dependencies": {
1116
"apollo-server-core": "^2.8.1",
1217
"apollo-server-express": "^2.8.1",
1318
"express": "^4.17.1",
1419
"graphql": "^14.4.2",
15-
"node-mocks-http": "^1.7.6"
16-
}
20+
"node-mocks-http": "^1.7.6",
21+
"typescript": "^3.5.3"
22+
},
23+
"keywords": [
24+
"GraphQL",
25+
"Apollo",
26+
"Server",
27+
"Javascript",
28+
"Testing",
29+
"Integration Testing"
30+
]
1731
}

src/index.js renamed to src/index.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import httpMocks from 'node-mocks-http';
55
import { print } from 'graphql';
66
import { convertNodeHttpToRequest, runHttpQuery } from 'apollo-server-core';
77

8-
import { type ApolloServer } from 'apollo-server-express';
9-
import { type DocumentNode } from 'graphql';
8+
import { ApolloServer } from 'apollo-server-express';
9+
import { DocumentNode } from 'graphql';
1010

1111
const mockRequest = (options = {}) =>
1212
httpMocks.createRequest({
@@ -21,13 +21,13 @@ type StringOrAst = string | DocumentNode;
2121
type TestClientConfig = {
2222
// The ApolloServer instance that will be used for handling the queries you run in your tests.
2323
// Must be an instance of the ApolloServer class from `apollo-server-express` (or a compatible subclass).
24-
apolloServer: ApolloServer,
24+
apolloServer: ApolloServer;
2525
// Extends the mocked Request object with additional keys.
2626
// Useful when your apolloServer `context` option is a callback that operates on the passed in `req` key,
2727
// and you want to inject data into that `req` object.
2828
// If you don't pass anything here, we provide a default request mock object for you.
2929
// See https://github.com/howardabrams/node-mocks-http#createrequest for all the default values that are included.
30-
extendMockRequest?: {}
30+
extendMockRequest?: {};
3131
};
3232

3333
// This function takes in an apollo server instance and returns a function that you can use to run operations
@@ -64,7 +64,10 @@ const createTestClient = ({
6464
const req = mockRequest(extendMockRequest);
6565
const res = mockResponse();
6666

67-
const graphQLOptions = apolloServer.createGraphQLServerOptions(req, res);
67+
const graphQLOptions = await apolloServer.createGraphQLServerOptions(
68+
req,
69+
res
70+
);
6871

6972
const { graphqlResponse } = await runHttpQuery([req, res], {
7073
method: 'POST',

tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist",
4+
"target": "es2016",
5+
"module": "commonjs",
6+
"esModuleInterop": true,
7+
"moduleResolution": "node",
8+
"removeComments": true,
9+
"strict": true,
10+
"declaration": true
11+
// "types": ["node"],
12+
},
13+
"include": ["./src/**/*"]
14+
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,11 @@ type-is@^1.6.16, type-is@^1.6.18, type-is@~1.6.17, type-is@~1.6.18:
10531053
media-typer "0.3.0"
10541054
mime-types "~2.1.24"
10551055

1056+
typescript@^3.5.3:
1057+
version "3.5.3"
1058+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
1059+
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==
1060+
10561061
[email protected], unpipe@~1.0.0:
10571062
version "1.0.0"
10581063
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"

0 commit comments

Comments
 (0)