Skip to content

Commit

Permalink
Only pass specific persistedQueries properties on `GraphQLServiceCo…
Browse files Browse the repository at this point in the history
…ntext`.

The `persistedQueries` attribute on the GraphQLServiceContext was originally
used by the operation registry, which shared the cache with it.  This is no
longer the case.

However, while we are continuing to expand the support of the interface for
`persistedQueries`, e.g. support for default TTL values on APQ cache in
#3623, we don't want to
continually expand the API surface of what we expose to the plugin API as
we're intending to deprecate its exposure in the future.

In this particular case, it certainly doesn't need to get the `ttl` default
values which are intended for APQ only.
  • Loading branch information
abernix committed Feb 14, 2020
1 parent 6005f50 commit a94f403
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
InMemoryLRUCache,
PrefixingKeyValueCache,
} from 'apollo-server-caching';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import {
ApolloServerPlugin,
GraphQLServiceContext,
} from 'apollo-server-plugin-base';
import runtimeSupportsUploads from './utils/runtimeSupportsUploads';

import {
Expand Down Expand Up @@ -558,19 +561,35 @@ export class ApolloServerBase {

protected async willStart() {
const { schema, schemaHash } = await this.schemaDerivedData;
const service: GraphQLServiceContext = {
schema: schema,
schemaHash: schemaHash,
engine: {
serviceID: this.engineServiceId,
apiKeyHash: this.engineApiKeyHash,
},
};

// The `persistedQueries` attribute on the GraphQLServiceContext was
// originally used by the operation registry, which shared the cache with
// it. This is no longer the case. However, while we are continuing to
// expand the support of the interface for `persistedQueries`, e.g. with
// additions like https://github.com/apollographql/apollo-server/pull/3623,
// we don't want to continually expand the API surface of what we expose
// to the plugin API. In this particular case, it certainly doesn't need
// to get the `ttl` default value which are intended for APQ only.
if (this.requestOptions.persistedQueries?.cache) {
service.persistedQueries = {
cache: this.requestOptions.persistedQueries.cache,
}
}

persistedQueries: this.requestOptions.persistedQueries,

This comment has been minimized.

Copy link
@evocateur

evocateur Mar 30, 2020

This looks like a copypasta error?

This comment has been minimized.

Copy link
@abernix

abernix Apr 9, 2020

Author Member

@evocateur Eeeps. Yup, a particularly bitter tasting, syntactically no-op, copy-pasta ingredient. 🍝

Thanks for noticing it and the ping! Fixed in 721ed04.

await Promise.all(
this.plugins.map(
plugin =>
plugin.serverWillStart &&
plugin.serverWillStart({
schema: schema,
schemaHash: schemaHash,
engine: {
serviceID: this.engineServiceId,
apiKeyHash: this.engineApiKeyHash,
},
persistedQueries: this.requestOptions.persistedQueries,
}),
plugin.serverWillStart(service),
),
);
}
Expand Down

0 comments on commit a94f403

Please sign in to comment.