Skip to content

Commit

Permalink
Update monorepo to Apollo Server 3 (#875)
Browse files Browse the repository at this point in the history
- Incorporate the upgrade of apollo-server-env too (see #876)
- Remove `subscriptions: false` from tests and docs
- Remove `engine: false` from a test (though I'm not super sure what it
  was doing)
- Don't depend on the apollo-server-env global types (removed in
  apollographql/apollo-server#5165)
- Remove a test of AS2-specific error handling behavior
- Delete some other stuff from tests until they pass

Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: David Glasser <[email protected]>
Co-authored-by: Trevor Scheer <[email protected]>
  • Loading branch information
4 people authored Jul 13, 2021
1 parent 89109b3 commit a262420
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 959 deletions.
7 changes: 0 additions & 7 deletions docs/source/gateway.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ const gateway = new ApolloGateway({
// Pass the ApolloGateway to the ApolloServer constructor
const server = new ApolloServer({
gateway,

// Disable subscriptions (not currently supported with ApolloGateway)
subscriptions: false,
});

server.listen().then(({ url }) => {
Expand Down Expand Up @@ -105,9 +102,6 @@ const gateway = new ApolloGateway({
const server = new ApolloServer({
gateway,
// Disable subscriptions (not currently supported with ApolloGateway)
subscriptions: false,
context: ({ req }) => {
// Get the user token from the headers
const token = req.headers.authorization || '';
Expand Down Expand Up @@ -187,7 +181,6 @@ const gateway = new ApolloGateway({

const server = new ApolloServer({
gateway,
subscriptions: false, // Must be disabled with the gateway; see above.
context() {
return { serverIds: [] };
},
Expand Down
2 changes: 0 additions & 2 deletions docs/source/quickstart-pt-2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ const gateway = new ApolloGateway();

const server = new ApolloServer({
gateway,
// Subscriptions are not currently supported in Apollo Federation
subscriptions: false
});

server.listen().then(({ url }) => {
Expand Down
4 changes: 0 additions & 4 deletions docs/source/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ const gateway = new ApolloGateway({

const server = new ApolloServer({
gateway,
// Subscriptions are not currently supported in Apollo Federation
subscriptions: false
});

server.listen().then(({ url }) => {
Expand Down Expand Up @@ -383,8 +381,6 @@ const gateway = new ApolloGateway({

const server = new ApolloServer({
gateway,
// Subscriptions are not currently supported in Apollo Federation
subscriptions: false
});

server.listen().then(({ url }) => {
Expand Down
2 changes: 0 additions & 2 deletions gateway-js/src/__tests__/gateway/composedSdl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ async function getSupergraphSdlGatewayServer() {
gateway: new ApolloGateway({
supergraphSdl: getTestingSupergraphSdl(),
}),
subscriptions: false,
engine: false,
});

await server.listen({ port: 0 });
Expand Down
38 changes: 0 additions & 38 deletions gateway-js/src/__tests__/gateway/executor.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import gql from 'graphql-tag';
import { ApolloGateway } from '../../';
import { ApolloServer } from "apollo-server";
import { fixtures } from 'apollo-federation-integration-testsuite';
import { Logger } from 'apollo-server-types';
import { fetch } from '../../__mocks__/apollo-server-env';
Expand Down Expand Up @@ -90,41 +89,4 @@ describe('ApolloGateway executor', () => {
expect(errors).toBeFalsy();
expect(data).toEqual({ me });
});

it('still sets the ApolloServer executor on load rejection', async () => {
const gateway = new ApolloGateway({
// Empty service list will trigger the gateway to crash on load, which is what we want.
serviceList: [],
logger,
});

const server = new ApolloServer({
gateway,
subscriptions: false,
logger,
});

// Ensure the throw happens to maintain the correctness of this test.
await expect(
server.executeOperation({ query: '{ __typename }' }),
).rejects.toThrow(
'This data graph is missing a valid configuration. More details may be available in the server logs.',
);

// Note: the original point of this test was to ensure that this field is
// set correctly even on schema load error, just in case the schema gets
// loaded properly later. But ApolloGateway has never managed to recover
// from a failure to load the schema, and Apollo Server v2.22 explicitly
// considers a server that failed to load the schema to have failed to start
// and there's no way to start it. So maybe this test doesn't matter any
// more. That said, perhaps it's nice to test the error handling.
expect(server.requestOptions.executor).toBe(gateway.executor);

expect(logger.error).toHaveBeenCalledTimes(1);
expect(logger.error).toHaveBeenCalledWith(
expect.stringMatching(
/Apollo Server was started implicitly.*Tried to load services from remote endpoints but none provided/,
),
);
});
});
11 changes: 1 addition & 10 deletions gateway-js/src/__tests__/gateway/reporting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import { Plugin, Config, Refs } from 'pretty-format';
import { Report, Trace } from 'apollo-reporting-protobuf';
import { fixtures } from 'apollo-federation-integration-testsuite';

// TODO: We should fix this another way, but for now adding this
// type declaration here to avoid a typing error in `apollo-link-http-common`
// due to us not dependeing on `dom` (or `webworker`) types.
declare global {
interface WindowOrWorkerGlobalScope {
fetch: typeof import('apollo-server-env')['fetch'];
}
}

// Normalize specific fields that change often (eg timestamps) to static values,
// to make snapshot testing viable. (If these helpers are more generally
// useful, they could be moved to a different file.)
Expand Down Expand Up @@ -128,7 +119,7 @@ describe('reporting', () => {
executor,
apollo: {
key: 'service:foo:bar',
graphVariant: 'current',
graphRef: 'foo@current',
},
plugins: [
ApolloServerPluginUsageReporting({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,7 @@ describe('didEncounterError', () => {
class MyDataSource extends RemoteGraphQLDataSource<MyContext> {
url = 'https://api.example.com/foo';

didEncounterError(
_error: Error,
_fetchRequest: Request,
_fetchResponse?: Response,
_context?: MyContext,
) {
didEncounterError() {
// a timestamp a la `Date.now()`
context.timingData.push({ time: 1616446845234 });
}
Expand Down
Loading

0 comments on commit a262420

Please sign in to comment.