apollo-server/packages/apollo-server-micro/src/microApollo.test.ts

55 lines
1.4 KiB
TypeScript
Raw Normal View History

import { microGraphql, microGraphiql } from './microApollo';
import 'mocha';
2017-06-05 15:58:10 -06:00
import micro, { send } from 'micro';
import {
router,
get,
post,
put,
patch,
del,
head,
options as opts,
} from 'microrouter';
import testSuite, {
schema,
CreateAppOptions,
} from 'apollo-server-integration-testsuite';
function createApp(options: CreateAppOptions) {
const graphqlOptions = (options && options.graphqlOptions) || { schema };
const graphiqlOptions = (options && options.graphiqlOptions) || {
endpointURL: '/graphql',
};
const graphqlHandler = microGraphql(graphqlOptions);
const graphiqlHandler = microGraphiql(graphiqlOptions);
return micro(
router(
get('/graphql', graphqlHandler),
post('/graphql', graphqlHandler),
put('/graphql', graphqlHandler),
patch('/graphql', graphqlHandler),
del('/graphql', graphqlHandler),
head('/graphql', graphqlHandler),
opts('/graphql', graphqlHandler),
get('/graphiql', graphiqlHandler),
post('/graphiql', graphiqlHandler),
put('/graphiql', graphiqlHandler),
patch('/graphiql', graphiqlHandler),
del('/graphiql', graphiqlHandler),
head('/graphiql', graphiqlHandler),
opts('/graphiql', graphiqlHandler),
(_, res) => send(res, 404, 'not found'),
),
);
}
describe('integration:Micro', () => {
testSuite(createApp);
});