|
1 | 1 | import express from 'express';
|
2 | 2 | import request from 'supertest';
|
3 | 3 | import compression, { filter as defaultFilter } from 'compression';
|
4 |
| -import { ApolloServer } from '../../index.js'; |
| 4 | +import { ApolloServer, BaseContext } from '../../index.js'; |
5 | 5 | import { expressMiddleware } from '../../express4/index.js';
|
6 | 6 | import { it, expect } from '@jest/globals';
|
7 | 7 | import resolvable from '@josephg/resolvable';
|
@@ -29,6 +29,27 @@ it('not calling start causes a clear error', async () => {
|
29 | 29 | );
|
30 | 30 | });
|
31 | 31 |
|
| 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 | + |
32 | 53 | // This test validates that you can use incremental delivery with the
|
33 | 54 | // `compression` package (which requires a hacky `res.flush()` call in the
|
34 | 55 | // middleware).
|
|
0 commit comments