Skip to content

Commit

Permalink
Stop testing Koa on Node.js v6 in order to update koa-bodyparser.
Browse files Browse the repository at this point in the history
Since Node.js v6 is no longer supported by the Node.js Foundation, it was
going to come to this sooner or later since transitive packages are inching
their ECMAScript compilation targets to more and more recent versions of the
language.

While Apollo Server itself will drop support for Node.js v6 in 3.x, the
current Koa integration necessitates a more immediate exception since, after
bringing #3229 (2dd0592), the `koa-bodyparser` package was updated to a new
major version which, itself, dropped Node.js 6 support.

That update to `koa-bodyparser`, which fixes an incorrect/malformed
`Content-length` header calculation is important enough on its own, but
there's also a [CVE][1] for the [`qs`][2] dependency, which makes it even
more pressing.

We should make sure both of those are included in Apollo Server, which
currently drives the underlying version of Koa for all users because of its
close coupling with Koa itself (via the `apollo-server-koa` package).

This doesn't necessarily mean that those who are still on Node.js v6 are
completely out of luck, since they could probably modify their
`package-lock.json` files to use an older copy of `koa-bodyparser`, but
anyone still using Node.js v6 should certainly make considerations - sooner
rather than later — about upgrading to more recent and more supported
versions of Node.js!

Luckily, this micro-framework-management will soon no longer be a concern
with Apollo Server, particularly because of the introduction of a transport
abstraction, which I've proposed in #3184.

Ref: #3184

[1]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-1000048
[2]: https://npm.im/qs

Fixes: #3050
  • Loading branch information
abernix committed Aug 31, 2019
1 parent 1abf851 commit 3be7e1b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The version headers in this history reflect the versions of Apollo Server itself

> [See complete versioning details.](https://github.com/apollographql/apollo-server/commit/92ea402a90bf9817c9b887707abbd77dcf5edcb4)
- `apollo-server-koa`: Update `koa-bodyparser` dependency from `v3.0.0` to `v4.2.1` to fix inaccurate `Content-length` calculation. [PR #3229](https://github.com/apollographql/apollo-server/pull/3229)
- `apollo-server-koa`: **Drop support for Node.js v6 within the Apollo Server Koa integration in order to update `koa-bodyparser` dependency from `v3.0.0` to `v4.2.1`.** [PR #TODO](https://github.com/apollographql/apollo-server/pull/TODO) [Issue #3050](https://github.com/apollographql/apollo-server/issues/3050) [PR #3229](https://github.com/apollographql/apollo-server/pull/3229)
- `apollo-server-express`: Use explicit return type for new `getMiddleware` method, in an effort to resolve [Issue #3222](https://github.com/apollographql/apollo-server/issues/3222) [PR #3230](https://github.com/apollographql/apollo-server/pull/3230)

### v2.9.1
Expand Down
45 changes: 32 additions & 13 deletions packages/apollo-server-koa/src/__tests__/ApolloServer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Koa from 'koa';

import http from 'http';

import request from 'request';
Expand All @@ -8,7 +6,7 @@ import fs from 'fs';
import { createApolloFetch } from 'apollo-fetch';

import { gql, AuthenticationError, Config } from 'apollo-server-core';
import { ApolloServer, ServerRegistration } from '../ApolloServer';
import { ServerRegistration } from '../ApolloServer';

import {
NODE_MAJOR_VERSION,
Expand All @@ -28,9 +26,20 @@ const resolvers = {
},
};

describe('apollo-server-koa', () => {
let server;
let httpServer;
// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped
// support for it and there was an important update to it which we brought in
// through https://github.com/apollographql/apollo-server/pull/3229.
// It's worth noting that Node.js v6 has been out of Long-Term-Support status
// for four months and is no longer recommended by the Node.js Foundation.
(
NODE_MAJOR_VERSION === 6 ?
describe.skip :
describe
)('apollo-server-koa', () => {
const { ApolloServer } = require('../ApolloServer');
const Koa = require('koa');
let server: ApolloServer;
let httpServer: http.Server;
testApolloServer(
async options => {
server = new ApolloServer(options);
Expand All @@ -48,23 +57,33 @@ describe('apollo-server-koa', () => {
);
});

describe('apollo-server-koa', () => {
let server: ApolloServer;

let app: Koa;
// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped
// support for it and there was an important update to it which we brought in
// through https://github.com/apollographql/apollo-server/pull/3229.
// It's worth noting that Node.js v6 has been out of Long-Term-Support status
// for four months and is no longer recommended by the Node.js Foundation.
(
NODE_MAJOR_VERSION === 6 ?
describe.skip :
describe
)('apollo-server-koa', () => {
const Koa = require('koa');
const { ApolloServer } = require('../ApolloServer');
let server: import('../ApolloServer').ApolloServer;
let app: import('koa');
let httpServer: http.Server;

async function createServer(
serverOptions: Config,
options: Partial<ServerRegistration> = {},
options: Partial<import('../ApolloServer').ServerRegistration> = {},
) {
server = new ApolloServer(serverOptions);
app = new Koa();

server.applyMiddleware({ ...options, app });

httpServer = await new Promise<http.Server>(resolve => {
const l = app.listen({ port: 0 }, () => resolve(l));
httpServer = await new Promise(resolve => {
const l: http.Server = app.listen({ port: 0 }, () => resolve(l));
});

return createServerInfo(server, httpServer);
Expand Down
63 changes: 38 additions & 25 deletions packages/apollo-server-koa/src/__tests__/datasource.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Koa from 'koa';
import KoaRouter from 'koa-router';

import http from 'http';

import { RESTDataSource } from 'apollo-datasource-rest';

import { createApolloFetch } from 'apollo-fetch';
import { ApolloServer } from '../ApolloServer';

import { createServerInfo } from 'apollo-server-integration-testsuite';
import { gql } from '../index';
import {
NODE_MAJOR_VERSION,
createServerInfo,
} from 'apollo-server-integration-testsuite';

import { gql } from 'apollo-server-core';

const restPort = 4002;

Expand Down Expand Up @@ -43,27 +43,40 @@ const resolvers = {
},
};

let restCalls = 0;
const restAPI = new Koa();
const router = new KoaRouter();
router.all('/id/:id', ctx => {
const id = ctx.params.id;
restCalls++;
ctx.set('Cache-Control', 'max-age=2000, public');
ctx.body = { id };
});
// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped
// support for it and there was an important update to it which we brought in
// through https://github.com/apollographql/apollo-server/pull/3229.
// It's worth noting that Node.js v6 has been out of Long-Term-Support status
// for four months and is no longer recommended by the Node.js Foundation.
(
NODE_MAJOR_VERSION === 6 ?
describe.skip :
describe
)('apollo-server-koa', () => {
const { ApolloServer } = require('../ApolloServer');
const Koa = require('koa');
const KoaRouter = require('koa-router');

let restCalls = 0;
const restAPI = new Koa();
const router = new KoaRouter();
router.all('/id/:id', ctx => {
const id = ctx.params.id;
restCalls++;
ctx.set('Cache-Control', 'max-age=2000, public');
ctx.body = { id };
});

router.all('/str/:id', ctx => {
const id = ctx.params.id;
restCalls++;
ctx.set('Cache-Control', 'max-age=2000, public');
ctx.body = id;
});
router.all('/str/:id', ctx => {
const id = ctx.params.id;
restCalls++;
ctx.set('Cache-Control', 'max-age=2000, public');
ctx.body = id;
});

restAPI.use(router.routes());
restAPI.use(router.allowedMethods());
restAPI.use(router.routes());
restAPI.use(router.allowedMethods());

describe('apollo-server-koa', () => {
let restServer;

beforeAll(async () => {
Expand All @@ -76,7 +89,7 @@ describe('apollo-server-koa', () => {
await restServer.close();
});

let server: ApolloServer;
let server: import('../ApolloServer').ApolloServer;
let httpServer: http.Server;

beforeEach(() => {
Expand Down
28 changes: 24 additions & 4 deletions packages/apollo-server-koa/src/__tests__/koaApollo.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Koa from 'koa';
import { ApolloServer } from '../ApolloServer';
import testSuite, {
NODE_MAJOR_VERSION,
schema as Schema,
CreateAppOptions,
} from 'apollo-server-integration-testsuite';
import { GraphQLOptions, Config } from 'apollo-server-core';

function createApp(options: CreateAppOptions = {}) {
const Koa = require('koa');
const { ApolloServer } = require('../ApolloServer');
const app = new Koa();

const server = new ApolloServer(
Expand All @@ -23,14 +24,33 @@ async function destroyApp(app) {
await new Promise(resolve => app.close(resolve));
}

describe('koaApollo', () => {
// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped
// support for it and there was an important update to it which we brought in
// through https://github.com/apollographql/apollo-server/pull/3229.
// It's worth noting that Node.js v6 has been out of Long-Term-Support status
// for four months and is no longer recommended by the Node.js Foundation.
(
NODE_MAJOR_VERSION === 6 ?
describe.skip :
describe
)('koaApollo', () => {
const { ApolloServer } = require('../ApolloServer');
it('throws error if called without schema', function() {
expect(() => new ApolloServer(undefined as GraphQLOptions)).toThrow(
'ApolloServer requires options.',
);
});
});

describe('integration:Koa', () => {
// If we're on Node.js v6, skip this test, since `koa-bodyparser` has dropped
// support for it and there was an important update to it which we brought in
// through https://github.com/apollographql/apollo-server/pull/3229.
// It's worth noting that Node.js v6 has been out of Long-Term-Support status
// for four months and is no longer recommended by the Node.js Foundation.
(
NODE_MAJOR_VERSION === 6 ?
describe.skip :
describe
)('integration:Koa', () => {
testSuite(createApp, destroyApp);
});

0 comments on commit 3be7e1b

Please sign in to comment.