2016-10-24 11:04:18 -07:00
|
|
|
import 'mocha';
|
|
|
|
import * as restify from 'restify';
|
2017-01-23 09:43:58 -08:00
|
|
|
import { graphiqlRestify, graphqlRestify } from './restifyApollo';
|
2017-01-24 12:54:34 +02:00
|
|
|
import testSuite, { schema, CreateAppOptions } from 'graphql-server-integration-testsuite';
|
2017-01-23 09:43:58 -08:00
|
|
|
import { expect } from 'chai';
|
2016-10-24 11:04:18 -07:00
|
|
|
import { GraphQLOptions } from 'graphql-server-core';
|
|
|
|
|
|
|
|
function createApp(options: CreateAppOptions = {}) {
|
|
|
|
const server = restify.createServer({
|
|
|
|
name: 'Restify Test Server',
|
|
|
|
});
|
|
|
|
|
2017-01-24 12:54:34 +02:00
|
|
|
options.graphqlOptions = options.graphqlOptions || { schema };
|
2016-10-24 11:04:18 -07:00
|
|
|
if (!options.excludeParser) {
|
|
|
|
server.use(restify.bodyParser());
|
2017-01-23 09:43:58 -08:00
|
|
|
server.use(restify.queryParser());
|
2016-10-24 11:04:18 -07:00
|
|
|
}
|
2017-01-23 09:43:58 -08:00
|
|
|
|
2016-10-24 11:04:18 -07:00
|
|
|
if (options.graphiqlOptions ) {
|
|
|
|
server.get('/graphiql', graphiqlRestify( options.graphiqlOptions ));
|
|
|
|
}
|
2017-01-23 09:43:58 -08:00
|
|
|
|
|
|
|
server.get('/graphql', graphqlRestify(options.graphqlOptions));
|
|
|
|
server.post('/graphql', graphqlRestify(options.graphqlOptions));
|
2016-10-24 12:39:17 -07:00
|
|
|
|
2016-10-24 11:04:18 -07:00
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('graphqlRestify', () => {
|
|
|
|
it('throws error if called without schema', () => {
|
|
|
|
expect(() => graphqlRestify(undefined as GraphQLOptions)).to.throw('Apollo Server requires options.');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws an error if called with more than one argument', () => {
|
|
|
|
expect(() => (<any>graphqlRestify)({}, 'x')).to.throw(
|
|
|
|
'Apollo Server expects exactly one argument, got 2');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generates a function if the options are ok', () => {
|
2017-01-24 12:54:34 +02:00
|
|
|
expect(() => graphqlRestify({ schema })).to.be.a('function');
|
2016-10-24 11:04:18 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('integration:Restify', () => {
|
|
|
|
testSuite(createApp);
|
|
|
|
});
|