2016-07-28 20:05:05 +02:00
|
|
|
import * as koa from 'koa';
|
|
|
|
import * as koaRouter from 'koa-router';
|
|
|
|
import * as koaBody from 'koa-bodyparser';
|
|
|
|
import { apolloKoa, graphiqlKoa } from './koaApollo';
|
2016-07-29 12:37:02 -07:00
|
|
|
import ApolloOptions from './apolloOptions';
|
|
|
|
import { expect } from 'chai';
|
2016-07-28 20:05:05 +02:00
|
|
|
|
|
|
|
import testSuite, { Schema, CreateAppOptions } from './integrations.test';
|
|
|
|
|
|
|
|
function createApp(options: CreateAppOptions = {}) {
|
|
|
|
const app = new koa();
|
|
|
|
const router = new koaRouter();
|
|
|
|
|
|
|
|
options.apolloOptions = options.apolloOptions || { schema: Schema };
|
|
|
|
|
|
|
|
if (!options.excludeParser) {
|
|
|
|
app.use(koaBody());
|
|
|
|
}
|
|
|
|
if (options.graphiqlOptions ) {
|
|
|
|
router.get('/graphiql', graphiqlKoa( options.graphiqlOptions ));
|
|
|
|
}
|
|
|
|
router.post('/graphql', apolloKoa( options.apolloOptions ));
|
|
|
|
app.use(router.routes());
|
|
|
|
app.use(router.allowedMethods());
|
|
|
|
return app.listen(3000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function destroyApp(app) {
|
|
|
|
app.close();
|
|
|
|
}
|
|
|
|
|
2016-07-29 12:37:02 -07:00
|
|
|
describe('expressApollo', () => {
|
|
|
|
it('throws error if called without schema', function(){
|
|
|
|
expect(() => apolloKoa(undefined as ApolloOptions)).to.throw('Apollo Server requires options.');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws an error if called with more than one argument', function(){
|
|
|
|
expect(() => (<any>apolloKoa)({}, 'x')).to.throw(
|
|
|
|
'Apollo Server expects exactly one argument, got 2');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-28 20:05:05 +02:00
|
|
|
describe('integration:Koa', () => {
|
|
|
|
testSuite(createApp, destroyApp);
|
|
|
|
});
|