-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail to compose when a service's federated SDL cannot be retrie… (#3867)
Previously, when attempting to compose a schema from a downstream service in unmanaged mode, the unavailability of a service would not cause composition to fail. Given a condition when the remaining downstream services are still composable (e.g. they do not depend on the unavailable service and it does not depend on them), this could still render a valid, but unintentionally partial schema. While a partial schema is in many ways fine, it will cause any client's queries against that now-missing part of the graph to suddenly become queries which will no longer validate, despite the fact that they may have previously been designed to fail gracefully during degradation of the service. Rather than simply logging errors with `console.error` in those conditions, we will now `throw` the errors. Thanks to changes in the upstream invokers' error handling (e.g.#3811), this `throw`-ing will now prevent unintentionally serving an incomplete graph.
- Loading branch information
Showing
3 changed files
with
79 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/apollo-gateway/src/__tests__/loadServicesFromRemoteEndpoint.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getServiceDefinitionsFromRemoteEndpoint } from '../loadServicesFromRemoteEndpoint'; | ||
import { mockLocalhostSDLQuery } from './integration/nockMocks'; | ||
import { RemoteGraphQLDataSource } from '../datasources'; | ||
import nock = require('nock'); | ||
|
||
describe('getServiceDefinitionsFromRemoteEndpoint', () => { | ||
it('errors when no URL was specified', async () => { | ||
const serviceSdlCache = new Map<string, string>(); | ||
const dataSource = new RemoteGraphQLDataSource({ url: '' }); | ||
const serviceList = [{ name: 'test', dataSource }]; | ||
await expect( | ||
getServiceDefinitionsFromRemoteEndpoint({ | ||
serviceList, | ||
serviceSdlCache, | ||
}), | ||
).rejects.toThrowError( | ||
"Tried to load schema for 'test' but no 'url' was specified.", | ||
); | ||
}); | ||
|
||
it('throws when the downstream service returns errors', async () => { | ||
const serviceSdlCache = new Map<string, string>(); | ||
const host = 'http://host-which-better-not-resolve'; | ||
const url = host + '/graphql'; | ||
|
||
const dataSource = new RemoteGraphQLDataSource({ url }); | ||
const serviceList = [{ name: 'test', url, dataSource }]; | ||
await expect( | ||
getServiceDefinitionsFromRemoteEndpoint({ | ||
serviceList, | ||
serviceSdlCache, | ||
}), | ||
).rejects.toThrowError(/^Couldn't load service definitions for "test" at http:\/\/host-which-better-not-resolve\/graphql: request to http:\/\/host-which-better-not-resolve\/graphql failed, reason: getaddrinfo ENOTFOUND/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters