apollo-server-core
Advanced tools
Comparing version 3.8.2 to 3.9.0
@@ -42,3 +42,2 @@ import { GraphQLSchema, DocumentNode } from 'graphql'; | ||
private ensurePluginInstantiation; | ||
private initializeDocumentStore; | ||
protected graphQLServerOptions(integrationContextArgument?: any): Promise<GraphQLServerOptions>; | ||
@@ -45,0 +44,0 @@ executeOperation(request: Omit<GraphQLRequest, 'query'> & { |
@@ -35,3 +35,3 @@ "use strict"; | ||
const resolvable_1 = __importDefault(require("@josephg/resolvable")); | ||
const apollo_server_caching_1 = require("apollo-server-caching"); | ||
const utils_keyvaluecache_1 = require("@apollo/utils.keyvaluecache"); | ||
const schemaHash_1 = require("./utils/schemaHash"); | ||
@@ -49,2 +49,3 @@ const requestPipeline_1 = require("./requestPipeline"); | ||
const uuid = __importStar(require("uuid")); | ||
const UnboundedCache_1 = require("./utils/UnboundedCache"); | ||
const NoIntrospection = (context) => ({ | ||
@@ -124,4 +125,16 @@ Field(node) { | ||
} | ||
if (requestOptions.cache === 'bounded') { | ||
requestOptions.cache = new utils_keyvaluecache_1.InMemoryLRUCache(); | ||
} | ||
if (!requestOptions.cache) { | ||
requestOptions.cache = new apollo_server_caching_1.InMemoryLRUCache(); | ||
requestOptions.cache = new UnboundedCache_1.UnboundedCache(); | ||
if (!isDev && | ||
(requestOptions.persistedQueries === undefined || | ||
(requestOptions.persistedQueries && | ||
!requestOptions.persistedQueries.cache))) { | ||
this.logger.warn('Persisted queries are enabled and are using an unbounded cache. Your server' + | ||
' is vulnerable to denial of service attacks via memory exhaustion. ' + | ||
'Set `cache: "bounded"` or `persistedQueries: false` in your ApolloServer ' + | ||
'constructor, or see https://go.apollo.dev/s/cache-backends for other alternatives.'); | ||
} | ||
} | ||
@@ -131,3 +144,3 @@ if (requestOptions.persistedQueries !== false) { | ||
requestOptions.persistedQueries = { | ||
cache: new apollo_server_caching_1.PrefixingKeyValueCache(apqCache, requestPipeline_1.APQ_CACHE_PREFIX), | ||
cache: new utils_keyvaluecache_1.PrefixingKeyValueCache(apqCache, requestPipeline_1.APQ_CACHE_PREFIX), | ||
...apqOtherOptions, | ||
@@ -378,6 +391,6 @@ }; | ||
documentStore: this.config.documentStore === undefined | ||
? this.initializeDocumentStore() | ||
? new utils_keyvaluecache_1.InMemoryLRUCache() | ||
: this.config.documentStore === null | ||
? null | ||
: new apollo_server_caching_1.PrefixingKeyValueCache(this.config.documentStore, `${uuid.v4()}:`), | ||
: new utils_keyvaluecache_1.PrefixingKeyValueCache(this.config.documentStore, `${uuid.v4()}:`), | ||
}; | ||
@@ -497,8 +510,2 @@ } | ||
} | ||
initializeDocumentStore() { | ||
return new apollo_server_caching_1.InMemoryLRUCache({ | ||
maxSize: Math.pow(2, 20) * 30, | ||
sizeCalculator: apollo_server_caching_1.InMemoryLRUCache.jsonBytesSizeCalculator, | ||
}); | ||
} | ||
async graphQLServerOptions(integrationContextArgument) { | ||
@@ -505,0 +512,0 @@ const { schema, schemaHash, documentStore } = await this._ensureStarted(); |
import type { GraphQLSchema, ValidationContext, GraphQLFieldResolver, DocumentNode, GraphQLError, GraphQLFormattedError, ParseOptions } from 'graphql'; | ||
import type { KeyValueCache } from 'apollo-server-caching'; | ||
import type { KeyValueCache } from '@apollo/utils.keyvaluecache'; | ||
import type { DataSource } from 'apollo-datasource'; | ||
@@ -4,0 +4,0 @@ import type { ApolloServerPlugin } from 'apollo-server-plugin-base'; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const dispatcher_1 = require("./utils/dispatcher"); | ||
const apollo_server_caching_1 = require("apollo-server-caching"); | ||
const utils_keyvaluecache_1 = require("@apollo/utils.keyvaluecache"); | ||
const createSHA_1 = __importDefault(require("./utils/createSHA")); | ||
@@ -49,4 +49,4 @@ const runHttpQuery_1 = require("./runHttpQuery"); | ||
persistedQueryCache = config.persistedQueries.cache; | ||
if (!(persistedQueryCache instanceof apollo_server_caching_1.PrefixingKeyValueCache)) { | ||
persistedQueryCache = new apollo_server_caching_1.PrefixingKeyValueCache(persistedQueryCache, exports.APQ_CACHE_PREFIX); | ||
if (!(persistedQueryCache instanceof utils_keyvaluecache_1.PrefixingKeyValueCache)) { | ||
persistedQueryCache = new utils_keyvaluecache_1.PrefixingKeyValueCache(persistedQueryCache, exports.APQ_CACHE_PREFIX); | ||
} | ||
@@ -93,3 +93,3 @@ queryHash = extensions.persistedQuery.sha256Hash; | ||
requestContext.document = parse(query, config.parseOptions); | ||
parsingDidEnd(); | ||
await parsingDidEnd(); | ||
} | ||
@@ -96,0 +96,0 @@ catch (syntaxError) { |
@@ -9,3 +9,3 @@ import type { GraphQLSchema, DocumentNode } from 'graphql'; | ||
export type { GraphQLSchemaModule }; | ||
import type { KeyValueCache } from 'apollo-server-caching'; | ||
import type { KeyValueCache } from '@apollo/utils.keyvaluecache'; | ||
export type { KeyValueCache }; | ||
@@ -15,3 +15,3 @@ export declare type Context<T = object> = T; | ||
export declare type PluginDefinition = ApolloServerPlugin | (() => ApolloServerPlugin); | ||
declare type BaseConfig = Pick<GraphQLOptions<Context>, 'formatError' | 'debug' | 'rootValue' | 'validationRules' | 'executor' | 'formatResponse' | 'fieldResolver' | 'dataSources' | 'cache' | 'logger' | 'allowBatchedHttpRequests'>; | ||
declare type BaseConfig = Pick<GraphQLOptions<Context>, 'formatError' | 'debug' | 'rootValue' | 'validationRules' | 'executor' | 'formatResponse' | 'fieldResolver' | 'dataSources' | 'logger' | 'allowBatchedHttpRequests'>; | ||
export declare type Unsubscriber = () => void; | ||
@@ -55,2 +55,3 @@ export declare type SchemaChangeCallback = (apiSchema: GraphQLSchema) => void; | ||
csrfPrevention?: CSRFPreventionOptions | boolean; | ||
cache?: KeyValueCache | 'bounded'; | ||
} | ||
@@ -57,0 +58,0 @@ export interface CSRFPreventionOptions { |
@@ -5,3 +5,3 @@ "use strict"; | ||
const schemaInstrumentation_1 = require("./schemaInstrumentation"); | ||
const apollo_server_caching_1 = require("apollo-server-caching"); | ||
const utils_keyvaluecache_1 = require("@apollo/utils.keyvaluecache"); | ||
const dispatcher_1 = require("./dispatcher"); | ||
@@ -50,3 +50,3 @@ const graphql_1 = require("graphql"); | ||
source: graphqlRequest.query, | ||
cache: new apollo_server_caching_1.InMemoryLRUCache(), | ||
cache: new utils_keyvaluecache_1.InMemoryLRUCache(), | ||
context, | ||
@@ -53,0 +53,0 @@ overallCachePolicy: (0, cachePolicy_1.newCachePolicy)(), |
{ | ||
"name": "apollo-server-core", | ||
"version": "3.8.2", | ||
"version": "3.9.0", | ||
"description": "Core engine for Apollo GraphQL server", | ||
@@ -28,2 +28,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@apollo/utils.keyvaluecache": "^1.0.1", | ||
"@apollo/utils.logger": "^1.0.0", | ||
@@ -36,9 +37,8 @@ "@apollo/utils.usagereporting": "^1.0.0", | ||
"@josephg/resolvable": "^1.0.0", | ||
"apollo-datasource": "^3.3.1", | ||
"apollo-datasource": "^3.3.2", | ||
"apollo-reporting-protobuf": "^3.3.1", | ||
"apollo-server-caching": "^3.3.0", | ||
"apollo-server-env": "^4.2.1", | ||
"apollo-server-errors": "^3.3.1", | ||
"apollo-server-plugin-base": "^3.6.0", | ||
"apollo-server-types": "^3.6.0", | ||
"apollo-server-plugin-base": "^3.6.1", | ||
"apollo-server-types": "^3.6.1", | ||
"async-retry": "^1.2.1", | ||
@@ -56,3 +56,3 @@ "fast-json-stable-stringify": "^2.1.0", | ||
}, | ||
"gitHead": "0b4e9349da13459cf279378cb311dcab4e3a7556" | ||
"gitHead": "36ecbb116cef0b8b62b3ee3b557c4db8c975a406" | ||
} |
@@ -17,3 +17,3 @@ import { addMocksToSchema } from '@graphql-tools/mock'; | ||
PrefixingKeyValueCache, | ||
} from 'apollo-server-caching'; | ||
} from '@apollo/utils.keyvaluecache'; | ||
import type { | ||
@@ -64,2 +64,3 @@ ApolloServerPlugin, | ||
import * as uuid from 'uuid'; | ||
import { UnboundedCache } from './utils/UnboundedCache'; | ||
@@ -265,6 +266,24 @@ const NoIntrospection = (context: ValidationContext) => ({ | ||
if (!requestOptions.cache) { | ||
if (requestOptions.cache === 'bounded') { | ||
requestOptions.cache = new InMemoryLRUCache(); | ||
} | ||
if (!requestOptions.cache) { | ||
requestOptions.cache = new UnboundedCache(); | ||
if ( | ||
!isDev && | ||
(requestOptions.persistedQueries === undefined || | ||
(requestOptions.persistedQueries && | ||
!requestOptions.persistedQueries.cache)) | ||
) { | ||
this.logger.warn( | ||
'Persisted queries are enabled and are using an unbounded cache. Your server' + | ||
' is vulnerable to denial of service attacks via memory exhaustion. ' + | ||
'Set `cache: "bounded"` or `persistedQueries: false` in your ApolloServer ' + | ||
'constructor, or see https://go.apollo.dev/s/cache-backends for other alternatives.', | ||
); | ||
} | ||
} | ||
if (requestOptions.persistedQueries !== false) { | ||
@@ -715,3 +734,3 @@ const { cache: apqCache = requestOptions.cache!, ...apqOtherOptions } = | ||
this.config.documentStore === undefined | ||
? this.initializeDocumentStore() | ||
? new InMemoryLRUCache() | ||
: this.config.documentStore === null | ||
@@ -913,16 +932,2 @@ ? null | ||
private initializeDocumentStore(): InMemoryLRUCache<DocumentNode> { | ||
return new InMemoryLRUCache<DocumentNode>({ | ||
// Create ~about~ a 30MiB InMemoryLRUCache. This is less than precise | ||
// since the technique to calculate the size of a DocumentNode is | ||
// only using JSON.stringify on the DocumentNode (and thus doesn't account | ||
// for unicode characters, etc.), but it should do a reasonable job at | ||
// providing a caching document store for most operations. | ||
// | ||
// If you want to tweak the max size, pass in your own documentStore. | ||
maxSize: Math.pow(2, 20) * 30, | ||
sizeCalculator: InMemoryLRUCache.jsonBytesSizeCalculator, | ||
}); | ||
} | ||
// This function is used by the integrations to generate the graphQLOptions | ||
@@ -929,0 +934,0 @@ // from an object containing the request and other integration specific |
@@ -10,3 +10,3 @@ import type { | ||
} from 'graphql'; | ||
import type { KeyValueCache } from 'apollo-server-caching'; | ||
import type { KeyValueCache } from '@apollo/utils.keyvaluecache'; | ||
import type { DataSource } from 'apollo-datasource'; | ||
@@ -13,0 +13,0 @@ import type { ApolloServerPlugin } from 'apollo-server-plugin-base'; |
@@ -56,3 +56,6 @@ import { | ||
import { Dispatcher } from './utils/dispatcher'; | ||
import { KeyValueCache, PrefixingKeyValueCache } from 'apollo-server-caching'; | ||
import { | ||
KeyValueCache, | ||
PrefixingKeyValueCache, | ||
} from '@apollo/utils.keyvaluecache'; | ||
@@ -249,3 +252,3 @@ export { GraphQLRequest, GraphQLResponse, GraphQLRequestContext }; | ||
requestContext.document = parse(query, config.parseOptions); | ||
parsingDidEnd(); | ||
await parsingDidEnd(); | ||
} catch (syntaxError) { | ||
@@ -252,0 +255,0 @@ await parsingDidEnd(syntaxError as Error); |
@@ -21,3 +21,3 @@ import type { GraphQLSchema, DocumentNode } from 'graphql'; | ||
import type { KeyValueCache } from 'apollo-server-caching'; | ||
import type { KeyValueCache } from '@apollo/utils.keyvaluecache'; | ||
export type { KeyValueCache }; | ||
@@ -44,3 +44,2 @@ | ||
| 'dataSources' | ||
| 'cache' | ||
| 'logger' | ||
@@ -115,2 +114,3 @@ | 'allowBatchedHttpRequests' | ||
csrfPrevention?: CSRFPreventionOptions | boolean; | ||
cache?: KeyValueCache | 'bounded'; | ||
} | ||
@@ -117,0 +117,0 @@ |
@@ -26,3 +26,3 @@ import type { | ||
} from 'apollo-server-plugin-base'; | ||
import { InMemoryLRUCache } from 'apollo-server-caching'; | ||
import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache'; | ||
import { Dispatcher } from './dispatcher'; | ||
@@ -29,0 +29,0 @@ import { getOperationAST, parse, validate as graphqlValidate } from 'graphql'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
954065
204
18214
- Removedapollo-server-caching@^3.3.0
- Removedapollo-server-caching@3.3.0(transitive)
Updatedapollo-datasource@^3.3.2
Updatedapollo-server-types@^3.6.1