Skip to content

Commit 025b5c9

Browse files
authored
Address TODO(AS4) in express4 directory (#6952)
Also make test subdirectory match source subdirectory.
1 parent 88968c5 commit 025b5c9

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

.changeset/light-kings-glow.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/server/src/__tests__/express/expressSpecific.test.ts renamed to packages/server/src/__tests__/express4/expressSpecific.test.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express from 'express';
22
import request from 'supertest';
33
import compression, { filter as defaultFilter } from 'compression';
4-
import { ApolloServer } from '../../index.js';
4+
import { ApolloServer, BaseContext } from '../../index.js';
55
import { expressMiddleware } from '../../express4/index.js';
66
import { it, expect } from '@jest/globals';
77
import resolvable from '@josephg/resolvable';
@@ -29,6 +29,27 @@ it('not calling start causes a clear error', async () => {
2929
);
3030
});
3131

32+
it('context optional only if TContext=BaseContext', async () => {
33+
const baseContextServer = new ApolloServer<BaseContext>({
34+
typeDefs: 'type Query{x:ID}',
35+
});
36+
await baseContextServer.start();
37+
const differentContextServer = new ApolloServer<{ x: number }>({
38+
typeDefs: 'type Query{x:ID}',
39+
});
40+
await differentContextServer.start();
41+
42+
// This is a typechecking test, so we don't actually do anything with these
43+
// middlewares.
44+
expressMiddleware(baseContextServer);
45+
expressMiddleware(baseContextServer, { context: async () => ({}) });
46+
expressMiddleware(differentContextServer, {
47+
context: async () => ({ x: 5 }),
48+
});
49+
// @ts-expect-error
50+
expressMiddleware(differentContextServer);
51+
});
52+
3253
// This test validates that you can use incremental delivery with the
3354
// `compression` package (which requires a hacky `res.flush()` call in the
3455
// middleware).

packages/server/src/express4/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ export interface ExpressMiddlewareOptions<TContext extends BaseContext> {
1717
context?: ContextFunction<[ExpressContextFunctionArgument], TContext>;
1818
}
1919

20-
// TODO(AS4): Figure out exact naming (eg is this Express-specific or just Node
21-
// HTTP?)
22-
// TODO(AS4): Write compilation tests about the context optionality stuff.
2320
export function expressMiddleware(
2421
server: ApolloServer<BaseContext>,
2522
options?: ExpressMiddlewareOptions<BaseContext>,

0 commit comments

Comments
 (0)