-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathexpressApollo.test.ts
More file actions
36 lines (31 loc) · 1.22 KB
/
Copy pathexpressApollo.test.ts
File metadata and controls
36 lines (31 loc) · 1.22 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
import * as express from 'express';
import * as bodyParser from 'body-parser';
import { graphqlExpress, graphiqlExpress } from './expressApollo';
import testSuite, { schema as Schema, CreateAppOptions } from 'apollo-server-integration-testsuite';
import { expect } from 'chai';
import { GraphQLOptions } from 'apollo-server-core';
import 'mocha';
function createApp(options: CreateAppOptions = {}) {
const app = express();
options.graphqlOptions = options.graphqlOptions || { schema: Schema };
if (!options.excludeParser) {
app.use('/graphql', bodyParser.json());
}
if (options.graphiqlOptions ) {
app.use('/graphiql', graphiqlExpress( options.graphiqlOptions ));
}
app.use('/graphql', graphqlExpress( options.graphqlOptions ));
return app;
}
describe('expressApollo', () => {
it('throws error if called without schema', function(){
expect(() => graphqlExpress(undefined as GraphQLOptions)).to.throw('Apollo Server requires options.');
});
it('throws an error if called with more than one argument', function(){
expect(() => (<any>graphqlExpress)({}, 'x')).to.throw(
'Apollo Server expects exactly one argument, got 2');
});
});
describe('integration:Express', () => {
testSuite(createApp);
});