Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: apollographql/apollo-server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: apollo-server@2.22.0
Choose a base ref
...
head repository: apollographql/apollo-server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: apollo-server@2.22.1
Choose a head ref
  • 2 commits
  • 16 files changed
  • 2 contributors

Commits on Mar 26, 2021

  1. Ensure startup errors are redacted even the first time (#5064)

    This is a regression in #4981. If the server start process is begun implicitly
    by the execution of an operation (ensureStarted inside graphQLServerOptions) and
    startup throws, the log-and-redact logic wasn't being invoked.
    
    Note that this case doesn't usually happen in practice, because:
    - If you're using `apollo-server`, startup is begun in `listen()` before you can
      serve requests
    - If you're using a serverless framework integration, startup is begun in the
      constructor
    - If you're using a non-serverless framework integration, the function you call
      to connect it to your framework begins startup with `ensureStarting()`
    
    So mostly this just affects the case that you're running `executeOperation`
    without calling `start()` or `listen()`, or maybe you have your own custom
    framework integration that doesn't call `ensureStarting()`. But it's still worth
    missing.
    
    Add some tests of this behavior and fix some TypeScript issues in the test file.
    glasser committed Mar 26, 2021
    Copy the full SHA
    97dbe7d View commit details
  2. Release

     - apollo-server-azure-functions@2.22.1
     - apollo-server-cloud-functions@2.22.1
     - apollo-server-cloudflare@2.22.1
     - apollo-server-core@2.22.1
     - apollo-server-express@2.22.1
     - apollo-server-fastify@2.22.1
     - apollo-server-hapi@2.22.1
     - apollo-server-integration-testsuite@2.22.1
     - apollo-server-koa@2.22.1
     - apollo-server-lambda@2.22.1
     - apollo-server-micro@2.22.1
     - apollo-server-testing@2.22.1
     - apollo-server@2.22.1
    glasser committed Mar 26, 2021
    Copy the full SHA
    6ad8f8f View commit details
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@ The version headers in this history reflect the versions of Apollo Server itself

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. With few exceptions, the format of the entry should follow convention (i.e., prefix with package name, use markdown `backtick formatting` for package names and code, suffix with a link to the change-set à la `[PR #YYY](https://link/pull/YYY)`, etc.). When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.

## v2.22.1

- `apollo-server-core`: Fix a regression in v2.22.0 where startup errors could be thrown as part of the GraphQL response instead of redacted in one edge case. [PR #5064](https://github.com/apollographql/apollo-server/pull/5064)

## v2.22.0

- Improve startup error handling by ensuring that your server has loaded its schema and executed its `serverWillStart` handlers successfully before starting an HTTP server. If you're using the `apollo-server` package, no code changes are necessary. If you're using an integration such as `apollo-server-express` that is not a "serverless framework", you can insert [`await server.start()`](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#start) between `server = new ApolloServer()` and `server.applyMiddleware`. (If you don't call `server.start()` yourself, your server will still work, but the previous behavior of starting a web server that may fail to load its schema still applies.) The serverless framework integrations (Lambda, Azure Functions, and Cloud Functions) do not support this functionality. While the protected method `willStart` still exists for backwards compatibility, you should replace calls to it with `start` or the new protected method `ensureStarting`. [PR #4981](https://github.com/apollographql/apollo-server/pull/4981)
2 changes: 1 addition & 1 deletion packages/apollo-server-azure-functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-azure-functions",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for Azure Functions",
"keywords": [
"GraphQL",
2 changes: 1 addition & 1 deletion packages/apollo-server-cloud-functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-cloud-functions",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for Google Cloud Functions",
"keywords": [
"GraphQL",
2 changes: 1 addition & 1 deletion packages/apollo-server-cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-cloudflare",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for Cloudflare workers",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-core",
"version": "2.22.0",
"version": "2.22.1",
"description": "Core engine for Apollo GraphQL server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
12 changes: 8 additions & 4 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
@@ -623,7 +623,12 @@ export class ApolloServerBase {
switch (this.state.phase) {
case 'initialized with gateway':
case 'initialized with schema':
await this._start();
try {
await this._start();
} catch {
// Any thrown error should transition us to 'failed to start', and
// we'll handle that on the next iteration of the while loop.
}
// continue the while loop
break;
case 'starting':
@@ -632,9 +637,8 @@ export class ApolloServerBase {
// continue the while loop
break;
case 'failed to start':
// First
// we log the error that prevented startup (which means it will get logged
// once for every GraphQL operation).
// First we log the error that prevented startup (which means it will
// get logged once for every GraphQL operation).
this.logStartupError(this.state.error);
// Now make the operation itself fail.
// We intentionally do not re-throw actual startup error as it may contain
57 changes: 55 additions & 2 deletions packages/apollo-server-core/src/__tests__/ApolloServerBase.test.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ import { ApolloServerBase } from '../ApolloServer';
import { buildServiceDefinition } from '@apollographql/apollo-tools';
import gql from 'graphql-tag';
import { Logger } from 'apollo-server-types';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import type { GraphQLSchema } from 'graphql';

const typeDefs = gql`
type Query {
@@ -36,7 +38,6 @@ describe('ApolloServerBase construction', () => {
});

it('succeeds when passed a graphVariant in construction', () => {
let serverBase;
expect(() =>
new ApolloServerBase({
typeDefs,
@@ -84,7 +85,7 @@ describe('ApolloServerBase construction', () => {
it('throws when a GraphQLSchema is not provided to the schema configuration option', () => {
expect(() => {
new ApolloServerBase({
schema: {},
schema: {} as GraphQLSchema,
});
}).toThrowErrorMatchingInlineSnapshot(
`"Expected {} to be a GraphQL schema."`,
@@ -100,6 +101,58 @@ describe('ApolloServerBase construction', () => {
});
});

describe('ApolloServerBase start', () => {
const failToStartPlugin: ApolloServerPlugin = {
async serverWillStart() {
throw Error('nope');
},
};
const redactedMessage =
'This data graph is missing a valid configuration. More details may be available in the server logs.';

it('start throws on startup error', async () => {
const server = new ApolloServerBase({
typeDefs,
resolvers,
plugins: [failToStartPlugin],
});
await expect(server.start()).rejects.toThrow('nope');
});

it('execute throws redacted message on implicit startup error', async () => {
const error = jest.fn();
const logger: Logger = {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error,
};

const server = new ApolloServerBase({
typeDefs,
resolvers,
plugins: [failToStartPlugin],
logger,
});
// Run the operation twice (the first will kick off the start process). We
// want to see the same error thrown and log message for the "kick it off"
// call as the subsequent call.
await expect(
server.executeOperation({ query: '{__typename}' }),
).rejects.toThrow(redactedMessage);
await expect(
server.executeOperation({ query: '{__typename}' }),
).rejects.toThrow(redactedMessage);
expect(error).toHaveBeenCalledTimes(2);
expect(error.mock.calls[0][0]).toMatch(
/Apollo Server was started implicitly.*nope/,
);
expect(error.mock.calls[1][0]).toMatch(
/Apollo Server was started implicitly.*nope/,
);
});
});

describe('ApolloServerBase executeOperation', () => {
it('returns error information without details by default', async () => {
const server = new ApolloServerBase({
2 changes: 1 addition & 1 deletion packages/apollo-server-express/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-express",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for Express and Connect",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-fastify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-fastify",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for Fastify",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-hapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-hapi",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for Hapi",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-integration-testsuite/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "apollo-server-integration-testsuite",
"private": true,
"version": "2.22.0",
"version": "2.22.1",
"description": "Apollo Server Integrations testsuite",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-koa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-koa",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for Koa",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-lambda/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-lambda",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for AWS Lambda",
"keywords": [
"GraphQL",
2 changes: 1 addition & 1 deletion packages/apollo-server-micro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-micro",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production-ready Node.js GraphQL server for Micro",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-testing",
"version": "2.22.0",
"version": "2.22.1",
"description": "Test utils for apollo-server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server",
"version": "2.22.0",
"version": "2.22.1",
"description": "Production ready GraphQL Server",
"author": "Apollo <opensource@apollographql.com>",
"main": "dist/index.js",