forked from apollographql/apollo-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApolloServer.test.ts
More file actions
58 lines (46 loc) · 1.23 KB
/
Copy pathApolloServer.test.ts
File metadata and controls
58 lines (46 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import fastify from 'fastify';
import http from 'http';
import { gql, Config } from 'apollo-server-core';
import { ApolloServer, ServerRegistration } from '../ApolloServer';
import { createServerInfo } from 'apollo-server-integration-testsuite';
const typeDefs = gql`
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'hi',
},
};
const port = 6666;
describe('apollo-server-fastify', () => {
let server: ApolloServer;
let app: fastify.FastifyInstance;
let httpServer: http.Server;
async function createServer(
serverOptions: Config,
options: Partial<ServerRegistration> = {},
) {
server = new ApolloServer(serverOptions);
app = fastify();
server.applyMiddleware({ ...options, app });
try {
await app.listen(port);
} catch (err) {
app.log.error('error in starting server', err);
process.exit(1);
}
httpServer = await app.server;
return createServerInfo(server, httpServer);
}
afterEach(async () => {
if (server) await server.stop();
if (httpServer) await httpServer.close();
});
describe('constructor', () => {
it('accepts typeDefs and resolvers', () => {
return createServer({ typeDefs, resolvers });
});
});
});