Socket
Socket
Sign inDemoInstall

apollo-server-core

Package Overview
Dependencies
22
Maintainers
1
Versions
314
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0 to 3.4.0-alpha.0

10

dist/ApolloServer.d.ts
import { GraphQLSchema, DocumentNode } from 'graphql';
import { InMemoryLRUCache } from 'apollo-server-caching';
import type { ApolloServerPlugin, LandingPage } from 'apollo-server-plugin-base';
import { GraphQLServerOptions } from './graphqlOptions';
import { Config } from './types';
import type { GraphQLServerOptions } from './graphqlOptions';
import type { Config, DocumentStore } from './types';
import { GraphQLRequest } from './requestPipeline';
import { SchemaHash } from 'apollo-server-types';
import type { SchemaHash } from 'apollo-server-types';
export declare type SchemaDerivedData = {
schema: GraphQLSchema;
schemaHash: SchemaHash;
documentStore?: InMemoryLRUCache<DocumentNode>;
documentStore: DocumentStore | null;
};

@@ -26,3 +25,2 @@ export declare class ApolloServerBase<ContextFunctionParams = any> {

private drainServers;
private experimental_approximateDocumentStoreMiB;
private stopOnTerminationSignals;

@@ -29,0 +27,0 @@ private landingPage;

71

dist/ApolloServer.js

@@ -31,5 +31,2 @@ "use strict";

});
function approximateObjectSize(obj) {
return Buffer.byteLength(JSON.stringify(obj), 'utf8');
}
class UnreachableCaseError extends Error {

@@ -42,2 +39,3 @@ constructor(val) {

constructor(config) {
var _a;
this.graphqlPath = '/graphql';

@@ -52,4 +50,7 @@ this.requestOptions = Object.create(null);

throw new Error('ApolloServer requires options.');
this.config = config;
const { context, resolvers, schema, modules, typeDefs, parseOptions = {}, introspection, plugins, gateway, apollo, stopOnTerminationSignals, mocks, mockEntireSchema, experimental_approximateDocumentStoreMiB, ...requestOptions } = config;
this.config = {
...config,
nodeEnv: (_a = config.nodeEnv) !== null && _a !== void 0 ? _a : process.env.NODE_ENV,
};
const { context, resolvers, schema, modules, typeDefs, parseOptions = {}, introspection, plugins, gateway, apollo, stopOnTerminationSignals, mocks, mockEntireSchema, documentStore, ...requestOptions } = this.config;
if (config.logger) {

@@ -68,3 +69,3 @@ this.logger = config.logger;

}
this.apolloConfig = determineApolloConfig_1.determineApolloConfig(apollo);
this.apolloConfig = (0, determineApolloConfig_1.determineApolloConfig)(apollo);
if (gateway && (modules || schema || typeDefs || resolvers)) {

@@ -75,12 +76,9 @@ throw new Error('Cannot define both `gateway` and any of: `modules`, `schema`, `typeDefs`, or `resolvers`');

this.context = context;
this.experimental_approximateDocumentStoreMiB =
experimental_approximateDocumentStoreMiB;
const nodeEnv = '__testing_nodeEnv__' in config
? config.__testing_nodeEnv__
: process.env.NODE_ENV;
const isDev = nodeEnv !== 'production';
const isDev = this.config.nodeEnv !== 'production';
this.stopOnTerminationSignals =
typeof stopOnTerminationSignals === 'boolean'
? stopOnTerminationSignals
: isNodeLike_1.default && nodeEnv !== 'test' && !this.serverlessFramework();
: isNodeLike_1.default &&
this.config.nodeEnv !== 'test' &&
!this.serverlessFramework();
if ((typeof introspection === 'boolean' && !introspection) ||

@@ -146,3 +144,3 @@ (introspection === undefined && !isDev)) {

const schemaManager = this.state.schemaManager;
const barrier = resolvable_1.default();
const barrier = (0, resolvable_1.default)();
this.state = {

@@ -232,3 +230,3 @@ phase: 'starting',

catch (error) {
this.state = { phase: 'failed to start', error };
this.state = { phase: 'failed to start', error: error };
throw error;

@@ -311,3 +309,3 @@ }

if (modules) {
const { schema, errors } = apollo_tools_1.buildServiceDefinition(modules);
const { schema, errors } = (0, apollo_tools_1.buildServiceDefinition)(modules);
if (errors && errors.length > 0) {

@@ -322,3 +320,3 @@ throw new Error(errors.map((error) => error.message).join('\n\n'));

const augmentedTypeDefs = Array.isArray(typeDefs) ? typeDefs : [typeDefs];
return schema_1.makeExecutableSchema({
return (0, schema_1.makeExecutableSchema)({
typeDefs: augmentedTypeDefs,

@@ -337,3 +335,3 @@ resolvers,

}
return mock_1.addMocksToSchema({
return (0, mock_1.addMocksToSchema)({
schema,

@@ -345,8 +343,9 @@ mocks: mocks === true || typeof mocks === 'undefined' ? {} : mocks,

generateSchemaDerivedData(schema) {
const schemaHash = schemaHash_1.generateSchemaHash(schema);
const documentStore = this.initializeDocumentStore();
const schemaHash = (0, schemaHash_1.generateSchemaHash)(schema);
return {
schema,
schemaHash,
documentStore,
documentStore: this.config.documentStore === undefined
? this.initializeDocumentStore()
: this.config.documentStore,
};

@@ -383,3 +382,3 @@ }

}
const barrier = resolvable_1.default();
const barrier = (0, resolvable_1.default)();
this.state = {

@@ -397,3 +396,3 @@ phase: 'draining',

catch (stopError) {
this.state = { phase: 'stopped', stopError };
this.state = { phase: 'stopped', stopError: stopError };
barrier.resolve();

@@ -414,6 +413,6 @@ throw stopError;

});
const alreadyHavePluginWithInternalId = (id) => this.plugins.some((p) => internalPlugin_1.pluginIsInternal(p) && p.__internal_plugin_id__() === id);
const alreadyHavePluginWithInternalId = (id) => this.plugins.some((p) => (0, internalPlugin_1.pluginIsInternal)(p) && p.__internal_plugin_id__() === id);
{
if (!alreadyHavePluginWithInternalId('CacheControl')) {
this.plugins.push(plugin_1.ApolloServerPluginCacheControl());
this.plugins.push((0, plugin_1.ApolloServerPluginCacheControl)());
}

@@ -425,3 +424,3 @@ }

if (this.apolloConfig.graphRef) {
this.plugins.unshift(plugin_1.ApolloServerPluginUsageReporting());
this.plugins.unshift((0, plugin_1.ApolloServerPluginUsageReporting)());
}

@@ -442,3 +441,3 @@ else {

const options = {};
this.plugins.push(plugin_1.ApolloServerPluginSchemaReporting(options));
this.plugins.push((0, plugin_1.ApolloServerPluginSchemaReporting)(options));
}

@@ -456,3 +455,3 @@ else {

if (!alreadyHavePlugin) {
this.plugins.push(plugin_1.ApolloServerPluginInlineTrace({ __onlyIfSchemaIsFederated: true }));
this.plugins.push((0, plugin_1.ApolloServerPluginInlineTrace)({ __onlyIfSchemaIsFederated: true }));
}

@@ -463,4 +462,4 @@ }

const plugin = isDev
? plugin_1.ApolloServerPluginLandingPageLocalDefault()
: plugin_1.ApolloServerPluginLandingPageProductionDefault();
? (0, plugin_1.ApolloServerPluginLandingPageLocalDefault)()
: (0, plugin_1.ApolloServerPluginLandingPageProductionDefault)();
if (!isImplicitlyInstallablePlugin(plugin)) {

@@ -475,4 +474,4 @@ throw Error('default landing page plugin should be implicitly installable?');

return new apollo_server_caching_1.InMemoryLRUCache({
maxSize: Math.pow(2, 20) * (this.experimental_approximateDocumentStoreMiB || 30),
sizeCalculator: approximateObjectSize,
maxSize: Math.pow(2, 20) * 30,
sizeCalculator: apollo_server_caching_1.InMemoryLRUCache.jsonBytesSizeCalculator,
});

@@ -514,3 +513,3 @@ }

else if (typeof options.context === 'object') {
options.context = runHttpQuery_1.cloneObject(options.context);
options.context = (0, runHttpQuery_1.cloneObject)(options.context);
}

@@ -524,3 +523,3 @@ const requestCtx = {

query: request.query && typeof request.query !== 'string'
? graphql_1.print(request.query)
? (0, graphql_1.print)(request.query)
: request.query,

@@ -537,5 +536,5 @@ },

debug: options.debug,
overallCachePolicy: cachePolicy_1.newCachePolicy(),
overallCachePolicy: (0, cachePolicy_1.newCachePolicy)(),
};
return requestPipeline_1.processGraphQLRequest(options, requestCtx);
return (0, requestPipeline_1.processGraphQLRequest)(options, requestCtx);
}

@@ -542,0 +541,0 @@ getLandingPage() {

@@ -1,3 +0,3 @@

import { ApolloConfig, ApolloConfigInput } from 'apollo-server-types';
import type { ApolloConfig, ApolloConfigInput } from 'apollo-server-types';
export declare function determineApolloConfig(input: ApolloConfigInput | undefined): ApolloConfig;
//# sourceMappingURL=determineApolloConfig.d.ts.map

@@ -19,3 +19,3 @@ "use strict";

if (apolloConfig.key) {
apolloConfig.keyHash = createSHA_1.default('sha512')
apolloConfig.keyHash = (0, createSHA_1.default)('sha512')
.update(apolloConfig.key)

@@ -22,0 +22,0 @@ .digest('hex');

@@ -1,6 +0,7 @@

import { GraphQLSchema, ValidationContext, GraphQLFieldResolver, DocumentNode, GraphQLError, GraphQLFormattedError, ParseOptions } from 'graphql';
import { KeyValueCache, InMemoryLRUCache } from 'apollo-server-caching';
import { DataSource } from 'apollo-datasource';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import { GraphQLExecutor, ValueOrPromise, GraphQLResponse, GraphQLRequestContext, Logger, SchemaHash } from 'apollo-server-types';
import type { GraphQLSchema, ValidationContext, GraphQLFieldResolver, DocumentNode, GraphQLError, GraphQLFormattedError, ParseOptions } from 'graphql';
import type { KeyValueCache } from 'apollo-server-caching';
import type { DataSource } from 'apollo-datasource';
import type { ApolloServerPlugin } from 'apollo-server-plugin-base';
import type { GraphQLExecutor, ValueOrPromise, GraphQLResponse, GraphQLRequestContext, Logger, SchemaHash } from 'apollo-server-types';
import type { DocumentStore } from './types';
export interface GraphQLServerOptions<TContext = Record<string, any>, TRootValue = any> {

@@ -22,5 +23,5 @@ schema: GraphQLSchema;

plugins?: ApolloServerPlugin[];
documentStore?: InMemoryLRUCache<DocumentNode>;
documentStore?: DocumentStore | null;
parseOptions?: ParseOptions;
__testing_nodeEnv__?: string | undefined;
nodeEnv?: string;
}

@@ -27,0 +28,0 @@ export declare type DataSources<TContext> = {

@@ -1,2 +0,2 @@

export { runHttpQuery, HttpQueryRequest, HttpQueryError } from './runHttpQuery';
export { runHttpQuery, HttpQueryRequest, HttpQueryError, isHttpQueryError, } from './runHttpQuery';
export { default as GraphQLOptions, resolveGraphqlOptions, PersistedQueryOptions, } from './graphqlOptions';

@@ -8,5 +8,5 @@ export { ApolloError, toApolloError, SyntaxError, ValidationError, AuthenticationError, ForbiddenError, UserInputError, formatApolloErrors, } from 'apollo-server-errors';

export { GraphQLServiceContext, GraphQLRequest, VariableValues, GraphQLResponse, GraphQLRequestMetrics, GraphQLRequestContext, ValidationRule, GraphQLExecutor, GraphQLExecutionResult, } from 'apollo-server-types';
import { DocumentNode } from 'graphql';
import type { DocumentNode } from 'graphql';
export declare const gql: (template: TemplateStringsArray | string, ...substitutions: any[]) => DocumentNode;
export * from './plugin';
//# sourceMappingURL=index.d.ts.map

@@ -16,6 +16,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.gql = exports.ApolloServerBase = exports.convertNodeHttpToRequest = exports.formatApolloErrors = exports.UserInputError = exports.ForbiddenError = exports.AuthenticationError = exports.ValidationError = exports.SyntaxError = exports.toApolloError = exports.ApolloError = exports.resolveGraphqlOptions = exports.HttpQueryError = exports.runHttpQuery = void 0;
exports.gql = exports.ApolloServerBase = exports.convertNodeHttpToRequest = exports.formatApolloErrors = exports.UserInputError = exports.ForbiddenError = exports.AuthenticationError = exports.ValidationError = exports.SyntaxError = exports.toApolloError = exports.ApolloError = exports.resolveGraphqlOptions = exports.isHttpQueryError = exports.HttpQueryError = exports.runHttpQuery = void 0;
var runHttpQuery_1 = require("./runHttpQuery");
Object.defineProperty(exports, "runHttpQuery", { enumerable: true, get: function () { return runHttpQuery_1.runHttpQuery; } });
Object.defineProperty(exports, "HttpQueryError", { enumerable: true, get: function () { return runHttpQuery_1.HttpQueryError; } });
Object.defineProperty(exports, "isHttpQueryError", { enumerable: true, get: function () { return runHttpQuery_1.isHttpQueryError; } });
var graphqlOptions_1 = require("./graphqlOptions");

@@ -22,0 +23,0 @@ Object.defineProperty(exports, "resolveGraphqlOptions", { enumerable: true, get: function () { return graphqlOptions_1.resolveGraphqlOptions; } });

/// <reference types="node" />
import { IncomingMessage } from 'http';
import type { IncomingMessage } from 'http';
import { Request } from 'apollo-server-env';
export declare function convertNodeHttpToRequest(req: IncomingMessage): Request;
//# sourceMappingURL=nodeHttpToRequest.d.ts.map

@@ -54,3 +54,3 @@ "use strict";

if (isRestricted(requestContext.overallCachePolicy)) {
const fakeFieldPolicy = cachePolicy_1.newCachePolicy();
const fakeFieldPolicy = (0, cachePolicy_1.newCachePolicy)();
return {

@@ -70,6 +70,6 @@ willResolveField({ info }) {

willResolveField({ info }) {
const fieldPolicy = cachePolicy_1.newCachePolicy();
const fieldPolicy = (0, cachePolicy_1.newCachePolicy)();
let inheritMaxAge = false;
const targetType = graphql_1.getNamedType(info.returnType);
if (graphql_1.isCompositeType(targetType)) {
const targetType = (0, graphql_1.getNamedType)(info.returnType);
if ((0, graphql_1.isCompositeType)(targetType)) {
const typeAnnotation = memoizedCacheAnnotationFromType(targetType);

@@ -99,3 +99,3 @@ fieldPolicy.replace(typeAnnotation);

if (fieldPolicy.maxAge === undefined &&
((graphql_1.isCompositeType(targetType) && !inheritMaxAge) ||
(((0, graphql_1.isCompositeType)(targetType) && !inheritMaxAge) ||
!info.path.prev)) {

@@ -105,3 +105,3 @@ fieldPolicy.restrict({ maxAge: defaultMaxAge });

if (__testing__cacheHints && isRestricted(fieldPolicy)) {
const path = graphql_1.responsePathAsArray(info.path).join('.');
const path = (0, graphql_1.responsePathAsArray)(info.path).join('.');
if (__testing__cacheHints.has(path)) {

@@ -108,0 +108,0 @@ throw Error("shouldn't happen: addHint should only be called once per path");

@@ -15,3 +15,3 @@ "use strict";

if (enabled === null) {
enabled = schemaIsFederated_1.schemaIsFederated(schema);
enabled = (0, schemaIsFederated_1.schemaIsFederated)(schema);
if (enabled) {

@@ -18,0 +18,0 @@ logger.info('Enabling inline tracing for this federated service. To disable, use ' +

import { renderPlaygroundPage } from '@apollographql/graphql-playground-html';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import type { ApolloServerPlugin } from 'apollo-server-plugin-base';
export declare type ApolloServerPluginLandingPageGraphQLPlaygroundOptions = Parameters<typeof renderPlaygroundPage>[0];
export declare function ApolloServerPluginLandingPageGraphQLPlayground(options?: ApolloServerPluginLandingPageGraphQLPlaygroundOptions): ApolloServerPlugin;
//# sourceMappingURL=index.d.ts.map

@@ -12,3 +12,3 @@ "use strict";

return {
html: graphql_playground_html_1.renderPlaygroundPage({
html: (0, graphql_playground_html_1.renderPlaygroundPage)({
version: defaultPlaygroundVersion,

@@ -15,0 +15,0 @@ ...options,

@@ -7,3 +7,3 @@ "use strict";

const serviceType = schema.getType('_Service');
if (!graphql_1.isObjectType(serviceType)) {
if (!(0, graphql_1.isObjectType)(serviceType)) {
return false;

@@ -16,3 +16,3 @@ }

const sdlFieldType = sdlField.type;
if (!graphql_1.isScalarType(sdlFieldType)) {
if (!(0, graphql_1.isScalarType)(sdlFieldType)) {
return false;

@@ -19,0 +19,0 @@ }

@@ -14,3 +14,3 @@ "use strict";

function ApolloServerPluginSchemaReporting({ initialDelayMaxMs, overrideReportedSchema, endpointUrl, fetcher, } = Object.create(null)) {
const bootId = uuid_1.v4();
const bootId = (0, uuid_1.v4)();
return {

@@ -33,3 +33,3 @@ __internal_plugin_id__() {

try {
const validationErrors = graphql_1.validateSchema(graphql_1.buildSchema(overrideReportedSchema, { noLocation: true }));
const validationErrors = (0, graphql_1.validateSchema)((0, graphql_1.buildSchema)(overrideReportedSchema, { noLocation: true }));
if (validationErrors.length) {

@@ -44,3 +44,3 @@ throw new Error(validationErrors.map((error) => error.message).join('\n'));

}
if (schemaIsFederated_1.schemaIsFederated(schema)) {
if ((0, schemaIsFederated_1.schemaIsFederated)(schema)) {
throw Error([

@@ -77,3 +77,3 @@ 'Schema reporting is not yet compatible with federated services.',

}
const coreSchema = (_a = overrideReportedSchema !== null && overrideReportedSchema !== void 0 ? overrideReportedSchema : coreSupergraphSdl) !== null && _a !== void 0 ? _a : graphql_1.printSchema(apiSchema);
const coreSchema = (_a = overrideReportedSchema !== null && overrideReportedSchema !== void 0 ? overrideReportedSchema : coreSupergraphSdl) !== null && _a !== void 0 ? _a : (0, graphql_1.printSchema)(apiSchema);
const coreSchemaHash = computeCoreSchemaHash(coreSchema);

@@ -108,5 +108,5 @@ const schemaReport = {

function computeCoreSchemaHash(schema) {
return createSHA_1.default('sha256').update(schema).digest('hex');
return (0, createSHA_1.default)('sha256').update(schema).digest('hex');
}
exports.computeCoreSchemaHash = computeCoreSchemaHash;
//# sourceMappingURL=index.js.map
import { fetch } from 'apollo-server-env';
import { Logger } from 'apollo-server-types';
import { SchemaReport, ReportSchemaResponse } from './operations';
import type { Logger } from 'apollo-server-types';
import type { SchemaReport, ReportSchemaResponse } from './operations';
export declare const schemaReportGql: string;

@@ -5,0 +5,0 @@ export declare class SchemaReporter {

@@ -7,3 +7,3 @@ "use strict";

const graphql_1 = require("graphql");
exports.schemaReportGql = graphql_1.print(__1.gql `
exports.schemaReportGql = (0, graphql_1.print)((0, __1.gql) `
mutation SchemaReport($report: SchemaReport!, $coreSchema: String) {

@@ -10,0 +10,0 @@ reportSchema(report: $report, coreSchema: $coreSchema) {

import { GraphQLError, GraphQLResolveInfo } from 'graphql';
import { Trace, google } from 'apollo-reporting-protobuf';
import { Logger } from 'apollo-server-types';
import type { Logger } from 'apollo-server-types';
export declare class TraceTreeBuilder {

@@ -5,0 +5,0 @@ private rootNode;

@@ -47,5 +47,5 @@ "use strict";

}
iterateOverTrace_1.iterateOverTrace(trace, traceNodeStats, false);
(0, iterateOverTrace_1.iterateOverTrace)(trace, traceNodeStats, false);
return hasErrors;
}
//# sourceMappingURL=defaultSendOperationsAsTrace.js.map

@@ -1,2 +0,2 @@

import { Trace } from 'apollo-reporting-protobuf';
import type { Trace } from 'apollo-reporting-protobuf';
export declare function iterateOverTrace(trace: Trace, f: (node: Trace.INode, path: ResponseNamePath) => boolean, includePath: boolean): void;

@@ -3,0 +3,0 @@ export interface ResponseNamePath {

@@ -1,3 +0,3 @@

import { GraphQLError, DocumentNode } from 'graphql';
import { GraphQLRequestContextDidResolveOperation, Logger, GraphQLRequestContext, GraphQLRequestContextWillSendResponse } from 'apollo-server-types';
import type { GraphQLError, DocumentNode } from 'graphql';
import type { GraphQLRequestContextDidResolveOperation, Logger, GraphQLRequestContext, GraphQLRequestContextWillSendResponse } from 'apollo-server-types';
import type { fetch, RequestAgent } from 'apollo-server-env';

@@ -4,0 +4,0 @@ import type { Trace } from 'apollo-reporting-protobuf';

import { Trace } from 'apollo-reporting-protobuf';
import { Headers } from 'apollo-server-env';
import { ApolloServerPluginUsageReportingOptions, SendValuesBaseOptions } from './options';
import type { ApolloServerPluginUsageReportingOptions, SendValuesBaseOptions } from './options';
import type { InternalApolloServerPlugin } from '../../internalPlugin';

@@ -5,0 +5,0 @@ export declare function ApolloServerPluginUsageReporting<TContext>(options?: ApolloServerPluginUsageReportingOptions<TContext>): InternalApolloServerPlugin;

@@ -67,6 +67,6 @@ "use strict";

const sendReportsImmediately = (_b = options.sendReportsImmediately) !== null && _b !== void 0 ? _b : serverlessFramework;
const signatureCache = signatureCache_1.createSignatureCache({ logger });
const signatureCache = (0, signatureCache_1.createSignatureCache)({ logger });
const reportDataByExecutableSchemaId = Object.create(null);
const overriddenExecutableSchemaId = options.overrideReportedSchema
? schemaReporting_1.computeCoreSchemaHash(options.overrideReportedSchema)
? (0, schemaReporting_1.computeCoreSchemaHash)(options.overrideReportedSchema)
: undefined;

@@ -79,3 +79,3 @@ let lastSeenExecutableSchemaToId;

let graphMightSupportTraces = true;
const sendOperationAsTrace = (_c = options.experimental_sendOperationAsTrace) !== null && _c !== void 0 ? _c : defaultSendOperationsAsTrace_1.defaultSendOperationsAsTrace();
const sendOperationAsTrace = (_c = options.experimental_sendOperationAsTrace) !== null && _c !== void 0 ? _c : (0, defaultSendOperationsAsTrace_1.defaultSendOperationsAsTrace)();
const includeTracesContributingToStats = (_d = options.internal_includeTracesContributingToStats) !== null && _d !== void 0 ? _d : false;

@@ -87,3 +87,3 @@ let stopped = false;

}
const id = schemaReporting_1.computeCoreSchemaHash(graphql_1.printSchema(schema));
const id = (0, schemaReporting_1.computeCoreSchemaHash)((0, graphql_1.printSchema)(schema));
lastSeenExecutableSchemaToId = {

@@ -125,3 +125,3 @@ executableSchema: schema,

}
report.endTime = traceTreeBuilder_1.dateToProtoTimestamp(new Date());
report.endTime = (0, traceTreeBuilder_1.dateToProtoTimestamp)(new Date());
const protobufError = apollo_reporting_protobuf_1.Report.verify(report);

@@ -138,3 +138,3 @@ if (protobufError) {

const messageBuffer = Buffer.from(message.buffer, message.byteOffset, message.byteLength);
zlib_1.gzip(messageBuffer, (err, gzipResult) => {
(0, zlib_1.gzip)(messageBuffer, (err, gzipResult) => {
if (err) {

@@ -149,3 +149,3 @@ reject(err);

const fetcher = (_a = options.fetcher) !== null && _a !== void 0 ? _a : apollo_server_env_1.fetch;
const response = await async_retry_1.default(async () => {
const response = await (0, async_retry_1.default)(async () => {
const curResponse = await fetcher((options.endpointUrl ||

@@ -247,3 +247,3 @@ 'https://usage-reporting.api.apollographql.com') +

if (variables) {
treeBuilder.trace.details = traceDetails_1.makeTraceDetails(variables, options.sendVariableValues, requestContext.source);
treeBuilder.trace.details = (0, traceDetails_1.makeTraceDetails)(variables, options.sendVariableValues, requestContext.source);
}

@@ -359,3 +359,3 @@ const clientInfo = (options.generateClientInfo || defaultGenerateClientInfo)(requestContext);

}
const cacheKey = signatureCache_1.signatureCacheKey(requestContext.queryHash, requestContext.operationName || '');
const cacheKey = (0, signatureCache_1.signatureCacheKey)(requestContext.queryHash, requestContext.operationName || '');
const cachedSignature = signatureCache.get(cacheKey);

@@ -362,0 +362,0 @@ if (cachedSignature) {

import LRUCache from 'lru-cache';
import { Logger } from 'apollo-server-types';
import type { Logger } from 'apollo-server-types';
export declare function createSignatureCache({ logger, }: {

@@ -4,0 +4,0 @@ logger: Logger;

@@ -151,3 +151,3 @@ "use strict";

};
iterateOverTrace_1.iterateOverTrace(trace, traceNodeStats, true);
(0, iterateOverTrace_1.iterateOverTrace)(trace, traceNodeStats, true);
if (hasError) {

@@ -154,0 +154,0 @@ this.queryLatencyStats.requestsWithErrorsCount++;

import { Trace } from 'apollo-reporting-protobuf';
import { VariableValueOptions } from './options';
import type { VariableValueOptions } from './options';
export declare function makeTraceDetails(variables: Record<string, any>, sendVariableValues?: VariableValueOptions, operationString?: string): Trace.Details;
//# sourceMappingURL=traceDetails.d.ts.map
import { GraphQLSchema, GraphQLFieldResolver, DocumentNode, GraphQLError, GraphQLFormattedError, ParseOptions } from 'graphql';
import { DataSource } from 'apollo-datasource';
import { PersistedQueryOptions } from './graphqlOptions';
import { GraphQLRequest, GraphQLResponse, GraphQLRequestContext, GraphQLExecutor, ValidationRule } from 'apollo-server-types';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import { InMemoryLRUCache } from 'apollo-server-caching';
import type { DataSource } from 'apollo-datasource';
import type { PersistedQueryOptions } from './graphqlOptions';
import type { GraphQLRequest, GraphQLResponse, GraphQLRequestContext, GraphQLExecutor, ValidationRule } from 'apollo-server-types';
import type { ApolloServerPlugin } from 'apollo-server-plugin-base';
export { GraphQLRequest, GraphQLResponse, GraphQLRequestContext };
import type { DocumentStore } from './types';
export declare const APQ_CACHE_PREFIX = "apq:";

@@ -20,3 +20,3 @@ export interface GraphQLRequestPipelineConfig<TContext> {

plugins?: ApolloServerPlugin[];
documentStore?: InMemoryLRUCache<DocumentNode>;
documentStore?: DocumentStore | null;
parseOptions?: ParseOptions;

@@ -23,0 +23,0 @@ }

@@ -17,6 +17,6 @@ "use strict";

function computeQueryHash(query) {
return createSHA_1.default('sha256').update(query).digest('hex');
return (0, createSHA_1.default)('sha256').update(query).digest('hex');
}
async function processGraphQLRequest(config, requestContext) {
var _a, _b;
var _a, _b, _c;
const logger = requestContext.logger || console;

@@ -77,3 +77,3 @@ const metrics = (requestContext.metrics =

logger.warn('An error occurred while attempting to read from the documentStore. ' +
(err === null || err === void 0 ? void 0 : err.message) || err);
((_a = err) === null || _a === void 0 ? void 0 : _a.message) || err);
}

@@ -104,5 +104,5 @@ }

}
const operation = graphql_1.getOperationAST(requestContext.document, request.operationName);
const operation = (0, graphql_1.getOperationAST)(requestContext.document, request.operationName);
requestContext.operation = operation || undefined;
requestContext.operationName = ((_a = operation === null || operation === void 0 ? void 0 : operation.name) === null || _a === void 0 ? void 0 : _a.value) || null;
requestContext.operationName = ((_b = operation === null || operation === void 0 ? void 0 : operation.name) === null || _b === void 0 ? void 0 : _b.value) || null;
try {

@@ -139,6 +139,6 @@ await dispatcher.invokeHook('didResolveOperation', requestContext);

}
schemaInstrumentation_1.enablePluginsForSchemaResolvers(config.schema);
(0, schemaInstrumentation_1.enablePluginsForSchemaResolvers)(config.schema);
try {
const result = await execute(requestContext);
const resultErrors = (_b = result.errors) === null || _b === void 0 ? void 0 : _b.map((e) => {
const resultErrors = (_c = result.errors) === null || _c === void 0 ? void 0 : _c.map((e) => {
var _a;

@@ -154,3 +154,3 @@ if (((_a = e.nodes) === null || _a === void 0 ? void 0 : _a.length) === 1 &&

`type "${e.nodes[0].type.type.name.value}!" must not be null.`))))) {
return apollo_server_errors_1.fromGraphQLError(e, {
return (0, apollo_server_errors_1.fromGraphQLError)(e, {
errorClass: apollo_server_errors_1.UserInputError,

@@ -183,3 +183,3 @@ });

function parse(query, parseOptions) {
return graphql_1.parse(query, parseOptions);
return (0, graphql_1.parse)(query, parseOptions);
}

@@ -191,3 +191,3 @@ function validate(document) {

}
return graphql_1.validate(config.schema, document, rules);
return (0, graphql_1.validate)(config.schema, document, rules);
}

@@ -211,3 +211,3 @@ async function execute(requestContext) {

else {
return await graphql_1.execute(executionArgs);
return await (0, graphql_1.execute)(executionArgs);
}

@@ -250,3 +250,3 @@ }

? err
: apollo_server_errors_1.fromGraphQLError(err, errorClass && {
: (0, apollo_server_errors_1.fromGraphQLError)(err, errorClass && {
errorClass,

@@ -273,3 +273,3 @@ }))),

function formatErrors(errors) {
return apollo_server_errors_1.formatApolloErrors(errors, {
return (0, apollo_server_errors_1.formatApolloErrors)(errors, {
formatter: config.formatError,

@@ -276,0 +276,0 @@ debug: requestContext.debug,

import { Request, Headers } from 'apollo-server-env';
import { default as GraphQLOptions } from './graphqlOptions';
import { WithRequired, GraphQLExecutionResult, ValueOrPromise } from 'apollo-server-types';
import type { WithRequired, GraphQLExecutionResult, ValueOrPromise } from 'apollo-server-types';
export interface HttpQueryRequest {

@@ -28,2 +28,3 @@ method: string;

}
export declare function isHttpQueryError(e: unknown): e is HttpQueryError;
export declare function throwHttpGraphQLError<E extends Error>(statusCode: number, errors: Array<E>, options?: Pick<GraphQLOptions, 'debug' | 'formatError'>, extensions?: GraphQLExecutionResult['extensions'], headers?: Headers): never;

@@ -30,0 +31,0 @@ export declare function runHttpQuery(handlerArguments: Array<any>, request: HttpQueryRequest): Promise<HttpQueryResponse>;

"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneObject = exports.processHTTPRequest = exports.runHttpQuery = exports.throwHttpGraphQLError = exports.HttpQueryError = void 0;
exports.cloneObject = exports.processHTTPRequest = exports.runHttpQuery = exports.throwHttpGraphQLError = exports.isHttpQueryError = exports.HttpQueryError = void 0;
const apollo_server_env_1 = require("apollo-server-env");

@@ -19,2 +20,7 @@ const graphqlOptions_1 = require("./graphqlOptions");

exports.HttpQueryError = HttpQueryError;
function isHttpQueryError(e) {
var _a;
return ((_a = e) === null || _a === void 0 ? void 0 : _a.name) === 'HttpQueryError';
}
exports.isHttpQueryError = isHttpQueryError;
function throwHttpGraphQLError(statusCode, errors, options, extensions, headers) {

@@ -31,3 +37,3 @@ const allHeaders = {

errors: options
? apollo_server_errors_1.formatApolloErrors(errors, {
? (0, apollo_server_errors_1.formatApolloErrors)(errors, {
debug: options.debug,

@@ -44,4 +50,5 @@ formatter: options.formatError,

exports.throwHttpGraphQLError = throwHttpGraphQLError;
const NODE_ENV = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : '';
async function runHttpQuery(handlerArguments, request) {
function debugFromNodeEnv(nodeEnv) {
function debugFromNodeEnv(nodeEnv = NODE_ENV) {
return nodeEnv !== 'production' && nodeEnv !== 'test';

@@ -51,14 +58,11 @@ }

try {
options = await graphqlOptions_1.resolveGraphqlOptions(request.options, ...handlerArguments);
options = await (0, graphqlOptions_1.resolveGraphqlOptions)(request.options, ...handlerArguments);
}
catch (e) {
return throwHttpGraphQLError(500, [e], {
debug: debugFromNodeEnv(process.env.NODE_ENV),
debug: debugFromNodeEnv(),
});
}
if (options.debug === undefined) {
const nodeEnv = '__testing_nodeEnv__' in options
? options.__testing_nodeEnv__
: process.env.NODE_ENV;
options.debug = debugFromNodeEnv(nodeEnv);
options.debug = debugFromNodeEnv(options.nodeEnv);
}

@@ -146,3 +150,3 @@ if (typeof options.context === 'function') {

metrics: {},
overallCachePolicy: cachePolicy_1.newCachePolicy(),
overallCachePolicy: (0, cachePolicy_1.newCachePolicy)(),
};

@@ -162,3 +166,3 @@ }

const requestContext = buildRequestContext(request);
const response = await requestPipeline_1.processGraphQLRequest(options, requestContext);
const response = await (0, requestPipeline_1.processGraphQLRequest)(options, requestContext);
if (response.http) {

@@ -176,3 +180,3 @@ for (const [name, value] of response.http.headers) {

return {
errors: apollo_server_errors_1.formatApolloErrors([error], options),
errors: (0, apollo_server_errors_1.formatApolloErrors)([error], options),
};

@@ -186,3 +190,3 @@ }

const requestContext = buildRequestContext(request);
const response = await requestPipeline_1.processGraphQLRequest(options, requestContext);
const response = await (0, requestPipeline_1.processGraphQLRequest)(options, requestContext);
if (response.errors && typeof response.data === 'undefined') {

@@ -189,0 +193,0 @@ return throwHttpGraphQLError(((_a = response.http) === null || _a === void 0 ? void 0 : _a.status) || 400, response.errors, undefined, response.extensions, (_b = response.http) === null || _b === void 0 ? void 0 : _b.headers);

@@ -9,3 +9,4 @@ import type { GraphQLSchema, DocumentNode, ParseOptions } from 'graphql';

export type { GraphQLSchemaModule };
export { KeyValueCache } from 'apollo-server-caching';
import type { KeyValueCache } from 'apollo-server-caching';
export type { KeyValueCache };
export declare type Context<T = object> = T;

@@ -34,2 +35,3 @@ export declare type ContextFunction<FunctionParams = any, ProducedContext = object> = (context: FunctionParams) => ValueOrPromise<Context<ProducedContext>>;

}
export declare type DocumentStore = KeyValueCache<DocumentNode>;
export interface Config<ContextFunctionParams = any> extends BaseConfig {

@@ -48,7 +50,7 @@ modules?: GraphQLSchemaModule[];

gateway?: GatewayInterface;
experimental_approximateDocumentStoreMiB?: number;
stopOnTerminationSignals?: boolean;
apollo?: ApolloConfigInput;
__testing_nodeEnv__?: string | undefined;
nodeEnv?: string;
documentStore?: DocumentStore | null;
}
//# sourceMappingURL=types.d.ts.map

@@ -1,2 +0,2 @@

import { AnyFunction, AnyFunctionMap } from 'apollo-server-types';
import type { AnyFunction, AnyFunctionMap } from 'apollo-server-types';
declare type Args<F> = F extends (...args: infer A) => any ? A : never;

@@ -3,0 +3,0 @@ declare type AsFunction<F> = F extends AnyFunction ? F : never;

@@ -1,4 +0,4 @@

import { CacheHint, WithRequired, GraphQLRequest, GraphQLRequestContextExecutionDidStart, GraphQLResponse, GraphQLRequestContextWillSendResponse, Logger } from 'apollo-server-types';
import type { CacheHint, WithRequired, GraphQLRequest, GraphQLRequestContextExecutionDidStart, GraphQLResponse, GraphQLRequestContextWillSendResponse, Logger } from 'apollo-server-types';
import { GraphQLSchema } from 'graphql/type';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import type { ApolloServerPlugin } from 'apollo-server-plugin-base';
declare type IPluginTestHarnessGraphqlRequest = WithRequired<GraphQLRequest, 'query'>;

@@ -5,0 +5,0 @@ declare type IPluginTestHarnessExecutionDidStart<TContext> = GraphQLRequestContextExecutionDidStart<TContext> & {

@@ -7,3 +7,2 @@ "use strict";

const dispatcher_1 = require("./dispatcher");
const schemaHash_1 = require("./schemaHash");
const graphql_1 = require("graphql");

@@ -28,3 +27,2 @@ const cachePolicy_1 = require("../cachePolicy");

}
const schemaHash = schemaHash_1.generateSchemaHash(schema);
let serverListener;

@@ -35,3 +33,3 @@ if (typeof pluginInstance.serverWillStart === 'function') {

schema,
schemaHash,
schemaHash: 'deprecated',
serverlessFramework: false,

@@ -50,3 +48,3 @@ apollo: {

schema,
schemaHash: schemaHash_1.generateSchemaHash(schema),
schemaHash: 'deprecated',
request: graphqlRequest,

@@ -57,3 +55,3 @@ metrics: Object.create(null),

context,
overallCachePolicy: cachePolicy_1.newCachePolicy(),
overallCachePolicy: (0, cachePolicy_1.newCachePolicy)(),
};

@@ -76,3 +74,3 @@ if (requestContext.source === undefined) {

try {
requestContext.document = graphql_1.parse(requestContext.source, undefined);
requestContext.document = (0, graphql_1.parse)(requestContext.source, undefined);
}

@@ -89,3 +87,3 @@ catch (syntaxError) {

const validationDidEnd = await dispatcher.invokeDidStartHook('validationDidStart', requestContext);
const validationErrors = graphql_1.validate(requestContext.schema, requestContext.document);
const validationErrors = (0, graphql_1.validate)(requestContext.schema, requestContext.document);
if (validationErrors.length !== 0) {

@@ -102,3 +100,3 @@ requestContext.errors = validationErrors;

}
const operation = graphql_1.getOperationAST(requestContext.document, requestContext.request.operationName);
const operation = (0, graphql_1.getOperationAST)(requestContext.document, requestContext.request.operationName);
requestContext.operation = operation || undefined;

@@ -116,3 +114,3 @@ requestContext.operationName = ((_a = operation === null || operation === void 0 ? void 0 : operation.name) === null || _a === void 0 ? void 0 : _a.value) || null;

Object.defineProperty(requestContext.context, schemaInstrumentation_1.symbolExecutionDispatcherWillResolveField, { value: invokeWillResolveField });
schemaInstrumentation_1.enablePluginsForSchemaResolvers(schema);
(0, schemaInstrumentation_1.enablePluginsForSchemaResolvers)(schema);
try {

@@ -119,0 +117,0 @@ requestContext.response = await executor(requestContext);

@@ -1,4 +0,4 @@

import { GraphQLSchema } from 'graphql/type';
import { SchemaHash } from 'apollo-server-types';
import type { GraphQLSchema } from 'graphql/type';
import type { SchemaHash } from 'apollo-server-types';
export declare function generateSchemaHash(schema: GraphQLSchema): SchemaHash;
//# sourceMappingURL=schemaHash.d.ts.map

@@ -13,5 +13,8 @@ "use strict";

function generateSchemaHash(schema) {
const introspectionQuery = utilities_1.getIntrospectionQuery();
const documentAST = language_1.parse(introspectionQuery);
const result = execution_1.execute(schema, documentAST);
const introspectionQuery = (0, utilities_1.getIntrospectionQuery)();
const document = (0, language_1.parse)(introspectionQuery);
const result = (0, execution_1.execute)({
schema,
document,
});
if (result &&

@@ -29,4 +32,4 @@ typeof result.then === 'function') {

const introspectionSchema = result.data.__schema;
const stringifiedSchema = fast_json_stable_stringify_1.default(introspectionSchema);
return createSHA_1.default('sha512')
const stringifiedSchema = (0, fast_json_stable_stringify_1.default)(introspectionSchema);
return (0, createSHA_1.default)('sha512')
.update(stringifiedSchema)

@@ -33,0 +36,0 @@ .digest('hex');

@@ -90,3 +90,3 @@ "use strict";

Object.entries(typeMap).forEach(([typeName, type]) => {
if (!type_1.getNamedType(type).name.startsWith('__') &&
if (!(0, type_1.getNamedType)(type).name.startsWith('__') &&
type instanceof type_1.GraphQLObjectType) {

@@ -93,0 +93,0 @@ const fields = type.getFields();

@@ -1,5 +0,5 @@

import { GraphQLSchema } from 'graphql';
import { ApolloConfig, GraphQLExecutor, GraphQLSchemaContext, Logger } from 'apollo-server-types';
import { GatewayInterface, Unsubscriber } from '../types';
import { SchemaDerivedData } from '../ApolloServer';
import type { GraphQLSchema } from 'graphql';
import type { ApolloConfig, GraphQLExecutor, GraphQLSchemaContext, Logger } from 'apollo-server-types';
import type { GatewayInterface, Unsubscriber } from '../types';
import type { SchemaDerivedData } from '../ApolloServer';
declare type SchemaDerivedDataProvider = (apiSchema: GraphQLSchema) => SchemaDerivedData;

@@ -6,0 +6,0 @@ export declare class SchemaManager {

@@ -21,4 +21,4 @@ "use strict";

apiSchema: options.apiSchema,
schemaDerivedData: options.schemaDerivedDataProvider(options.apiSchema),
};
options.schemaDerivedDataProvider(options.apiSchema);
}

@@ -54,3 +54,3 @@ }

apiSchema: this.modeSpecificState.apiSchema,
});
}, this.modeSpecificState.schemaDerivedData);
return null;

@@ -99,5 +99,6 @@ }

}
processSchemaLoadOrUpdateEvent(schemaContext) {
processSchemaLoadOrUpdateEvent(schemaContext, schemaDerivedData) {
if (!this.isStopped) {
this.schemaDerivedData = this.schemaDerivedDataProvider(schemaContext.apiSchema);
this.schemaDerivedData =
schemaDerivedData !== null && schemaDerivedData !== void 0 ? schemaDerivedData : this.schemaDerivedDataProvider(schemaContext.apiSchema);
this.schemaContext = schemaContext;

@@ -104,0 +105,0 @@ this.onSchemaLoadOrUpdateListeners.forEach((listener) => {

{
"name": "apollo-server-core",
"version": "3.3.0",
"version": "3.4.0-alpha.0",
"description": "Core engine for Apollo GraphQL server",

@@ -34,10 +34,10 @@ "main": "dist/index.js",

"@josephg/resolvable": "^1.0.0",
"apollo-datasource": "^3.1.0",
"apollo-datasource": "^3.2.0-alpha.0",
"apollo-graphql": "^0.9.0",
"apollo-reporting-protobuf": "^3.0.0",
"apollo-server-caching": "^3.1.0",
"apollo-server-env": "^4.0.3",
"apollo-server-errors": "^3.1.0",
"apollo-server-plugin-base": "^3.2.0",
"apollo-server-types": "^3.2.0",
"apollo-reporting-protobuf": "^3.1.0-alpha.0",
"apollo-server-caching": "^3.2.0-alpha.0",
"apollo-server-env": "^4.1.0-alpha.0",
"apollo-server-errors": "^3.2.0-alpha.0",
"apollo-server-plugin-base": "^3.3.0-alpha.0",
"apollo-server-types": "^3.3.0-alpha.0",
"async-retry": "^1.2.1",

@@ -54,3 +54,3 @@ "fast-json-stable-stringify": "^2.1.0",

},
"gitHead": "8524df3d3fe98b7ad625c48cb393cd4a59ec1476"
"gitHead": "119dac4fbe357661cad7163dfa643b02ab479b96"
}

@@ -25,5 +25,11 @@ import { addMocksToSchema } from '@graphql-tools/mock';

import { GraphQLServerOptions } from './graphqlOptions';
import type { GraphQLServerOptions } from './graphqlOptions';
import { Config, Context, ContextFunction, PluginDefinition } from './types';
import type {
Config,
Context,
ContextFunction,
DocumentStore,
PluginDefinition,
} from './types';

@@ -40,3 +46,3 @@ import { generateSchemaHash } from './utils/schemaHash';

import { buildServiceDefinition } from '@apollographql/apollo-tools';
import { Logger, SchemaHash, ApolloConfig } from 'apollo-server-types';
import type { Logger, SchemaHash, ApolloConfig } from 'apollo-server-types';
import { cloneObject } from './runHttpQuery';

@@ -71,8 +77,6 @@ import isNodeLike from './utils/isNodeLike';

function approximateObjectSize<T>(obj: T): number {
return Buffer.byteLength(JSON.stringify(obj), 'utf8');
}
export type SchemaDerivedData = {
schema: GraphQLSchema;
// Not a very useful schema hash (not the same one schema and usage reporting
// use!) but kept around for backwards compatibility.
schemaHash: SchemaHash;

@@ -82,3 +86,3 @@ // A store that, when enabled (default), will store the parsed and validated

// on the same operation to be executed immediately.
documentStore?: InMemoryLRUCache<DocumentNode>;
documentStore: DocumentStore | null;
};

@@ -146,3 +150,2 @@

private drainServers: (() => Promise<void>) | null = null;
private experimental_approximateDocumentStoreMiB: Config['experimental_approximateDocumentStoreMiB'];
private stopOnTerminationSignals: boolean;

@@ -154,3 +157,6 @@ private landingPage: LandingPage | null = null;

if (!config) throw new Error('ApolloServer requires options.');
this.config = config;
this.config = {
...config,
nodeEnv: config.nodeEnv ?? process.env.NODE_ENV,
};
const {

@@ -172,5 +178,5 @@ context,

mockEntireSchema,
experimental_approximateDocumentStoreMiB,
documentStore,
...requestOptions
} = config;
} = this.config;

@@ -208,15 +214,4 @@ // Setup logging facilities

this.context = context;
this.experimental_approximateDocumentStoreMiB =
experimental_approximateDocumentStoreMiB;
// Allow tests to override process.env.NODE_ENV. As a bonus, this means
// we're only reading the env var once in the constructor, which is faster
// than reading it over and over as each read is a syscall. Note that an
// explicit `__testing_nodeEnv__: undefined` overrides a set environment
// variable!
const nodeEnv =
'__testing_nodeEnv__' in config
? config.__testing_nodeEnv__
: process.env.NODE_ENV;
const isDev = nodeEnv !== 'production';
const isDev = this.config.nodeEnv !== 'production';

@@ -230,3 +225,5 @@ // We handle signals if it was explicitly requested, or if we're in Node,

? stopOnTerminationSignals
: isNodeLike && nodeEnv !== 'test' && !this.serverlessFramework();
: isNodeLike &&
this.config.nodeEnv !== 'test' &&
!this.serverlessFramework();

@@ -497,3 +494,3 @@ // if this is local dev, introspection should turned on

} catch (error) {
this.state = { phase: 'failed to start', error };
this.state = { phase: 'failed to start', error: error as Error };
throw error;

@@ -683,9 +680,14 @@ } finally {

// Initialize the document store. This cannot currently be disabled.
const documentStore = this.initializeDocumentStore();
return {
schema,
schemaHash,
documentStore,
// The DocumentStore is schema-derived because we put documents in it after
// checking that they pass GraphQL validation against the schema and use
// this to skip validation as well as parsing. So we can't reuse the same
// DocumentStore for different schemas because that might make us treat
// invalid operations as valid.
documentStore:
this.config.documentStore === undefined
? this.initializeDocumentStore()
: this.config.documentStore,
};

@@ -759,3 +761,3 @@ }

} catch (stopError) {
this.state = { phase: 'stopped', stopError };
this.state = { phase: 'stopped', stopError: stopError as Error };
barrier.resolve();

@@ -889,5 +891,6 @@ throw stopError;

// providing a caching document store for most operations.
maxSize:
Math.pow(2, 20) * (this.experimental_approximateDocumentStoreMiB || 30),
sizeCalculator: approximateObjectSize,
//
// If you want to tweak the max size, pass in your own documentStore.
maxSize: Math.pow(2, 20) * 30,
sizeCalculator: InMemoryLRUCache.jsonBytesSizeCalculator,
});

@@ -1016,3 +1019,3 @@ }

// integrations rely on this to tell the difference between "haven't called
// renderLandingPage yet" and "there is no landingß page").
// renderLandingPage yet" and "there is no landing page").
protected getLandingPage(): LandingPage | null {

@@ -1019,0 +1022,0 @@ this.assertStarted('getLandingPage');

@@ -1,2 +0,2 @@

import { ApolloConfig, ApolloConfigInput } from 'apollo-server-types';
import type { ApolloConfig, ApolloConfigInput } from 'apollo-server-types';
import createSHA from './utils/createSHA';

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

import {
import type {
GraphQLSchema,

@@ -10,6 +10,6 @@ ValidationContext,

} from 'graphql';
import { KeyValueCache, InMemoryLRUCache } from 'apollo-server-caching';
import { DataSource } from 'apollo-datasource';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import {
import type { KeyValueCache } from 'apollo-server-caching';
import type { DataSource } from 'apollo-datasource';
import type { ApolloServerPlugin } from 'apollo-server-plugin-base';
import type {
GraphQLExecutor,

@@ -22,2 +22,3 @@ ValueOrPromise,

} from 'apollo-server-types';
import type { DocumentStore } from './types';

@@ -44,2 +45,5 @@ /*

schema: GraphQLSchema;
/**
* @deprecated: a not particularly stable or useful hash of the schema.
*/
schemaHash: SchemaHash;

@@ -62,5 +66,5 @@ logger?: Logger;

plugins?: ApolloServerPlugin[];
documentStore?: InMemoryLRUCache<DocumentNode>;
documentStore?: DocumentStore | null;
parseOptions?: ParseOptions;
__testing_nodeEnv__?: string | undefined;
nodeEnv?: string;
}

@@ -67,0 +71,0 @@

@@ -1,2 +0,7 @@

export { runHttpQuery, HttpQueryRequest, HttpQueryError } from './runHttpQuery';
export {
runHttpQuery,
HttpQueryRequest,
HttpQueryError,
isHttpQueryError,
} from './runHttpQuery';

@@ -39,3 +44,3 @@ export {

// consistency between client and server gql tags
import { DocumentNode } from 'graphql';
import type { DocumentNode } from 'graphql';
import gqlTag from 'graphql-tag';

@@ -42,0 +47,0 @@ export const gql: (

@@ -1,2 +0,2 @@

import { IncomingMessage } from 'http';
import type { IncomingMessage } from 'http';
import { Request, Headers } from 'apollo-server-env';

@@ -3,0 +3,0 @@

import type { CacheAnnotation, CacheHint } from 'apollo-server-types';
import { CacheScope } from 'apollo-server-types';
import type { CacheScope } from 'apollo-server-types';
import {

@@ -22,3 +22,3 @@ DirectiveNode,

* using `@cacheControl` or `setCacheHint`. The default is 0, which means "not
* cachable". (That is: if you don't set `defaultMaxAge`, then every root
* cacheable". (That is: if you don't set `defaultMaxAge`, then every root
* field in your operation and every field with sub-fields must have a cache

@@ -25,0 +25,0 @@ * hint or the overall operation will not be cacheable.)

@@ -8,3 +8,3 @@ // This is the landing page plugin for GraphQL Playground. It wraps

import { renderPlaygroundPage } from '@apollographql/graphql-playground-html';
import {
import type {
ApolloServerPlugin,

@@ -11,0 +11,0 @@ GraphQLServerListener,

@@ -9,3 +9,3 @@ import os from 'os';

import { schemaIsFederated } from '../schemaIsFederated';
import { SchemaReport } from './operations';
import type { SchemaReport } from './operations';

@@ -106,3 +106,3 @@ export interface ApolloServerPluginSchemaReportingOptions {

'The schema provided to overrideReportedSchema failed to parse or ' +
`validate: ${err.message}`,
`validate: ${(err as Error).message}`,
);

@@ -109,0 +109,0 @@ }

import { gql } from '../..';
import { fetch, Headers, Request } from 'apollo-server-env';
import { GraphQLRequest, Logger } from 'apollo-server-types';
import type { GraphQLRequest, Logger } from 'apollo-server-types';
import { print } from 'graphql';
import {
import type {
SchemaReport,

@@ -7,0 +7,0 @@ SchemaReportMutationVariables,

@@ -5,3 +5,3 @@ // This class is a helper for ApolloServerPluginUsageReporting and

import { Trace, google } from 'apollo-reporting-protobuf';
import { Logger } from 'apollo-server-types';
import type { Logger } from 'apollo-server-types';

@@ -8,0 +8,0 @@ function internalError(message: string) {

@@ -1,2 +0,2 @@

import { Trace } from 'apollo-reporting-protobuf';
import type { Trace } from 'apollo-reporting-protobuf';

@@ -3,0 +3,0 @@ /**

@@ -1,3 +0,3 @@

import { GraphQLError, DocumentNode } from 'graphql';
import {
import type { GraphQLError, DocumentNode } from 'graphql';
import type {
GraphQLRequestContextDidResolveOperation,

@@ -4,0 +4,0 @@ Logger,

@@ -7,3 +7,3 @@ import os from 'os';

import { Response, fetch, Headers } from 'apollo-server-env';
import {
import type {
GraphQLRequestListener,

@@ -20,3 +20,3 @@ GraphQLServerListener,

import { createSignatureCache, signatureCacheKey } from './signatureCache';
import {
import type {
ApolloServerPluginUsageReportingOptions,

@@ -23,0 +23,0 @@ SendValuesBaseOptions,

import LRUCache from 'lru-cache';
import { Logger } from 'apollo-server-types';
import type { Logger } from 'apollo-server-types';

@@ -4,0 +4,0 @@ export function createSignatureCache({

import { Trace } from 'apollo-reporting-protobuf';
import { VariableValueOptions } from './options';
import type { VariableValueOptions } from './options';

@@ -4,0 +4,0 @@ // Creates trace details from request variables, given a specification for modifying

@@ -16,4 +16,4 @@ import {

} from 'graphql';
import { DataSource } from 'apollo-datasource';
import { PersistedQueryOptions } from './graphqlOptions';
import type { DataSource } from 'apollo-datasource';
import type { PersistedQueryOptions } from './graphqlOptions';
import {

@@ -34,3 +34,3 @@ symbolExecutionDispatcherWillResolveField,

} from 'apollo-server-errors';
import {
import type {
GraphQLRequest,

@@ -43,3 +43,3 @@ GraphQLResponse,

} from 'apollo-server-types';
import {
import type {
ApolloServerPlugin,

@@ -59,7 +59,3 @@ GraphQLRequestListener,

import { Dispatcher } from './utils/dispatcher';
import {
InMemoryLRUCache,
KeyValueCache,
PrefixingKeyValueCache,
} from 'apollo-server-caching';
import { KeyValueCache, PrefixingKeyValueCache } from 'apollo-server-caching';

@@ -70,2 +66,3 @@ export { GraphQLRequest, GraphQLResponse, GraphQLRequestContext };

import { HttpQueryError } from './runHttpQuery';
import type { DocumentStore } from './types';
import { Headers } from 'apollo-server-env';

@@ -98,3 +95,3 @@

plugins?: ApolloServerPlugin[];
documentStore?: InMemoryLRUCache<DocumentNode>;
documentStore?: DocumentStore | null;

@@ -226,3 +223,3 @@ parseOptions?: ParseOptions;

'An error occurred while attempting to read from the documentStore. ' +
err?.message || err,
(err as Error)?.message || err,
);

@@ -244,4 +241,6 @@ }

} catch (syntaxError) {
await parsingDidEnd(syntaxError);
return await sendErrorResponse(syntaxError, SyntaxError);
await parsingDidEnd(syntaxError as Error);
// XXX: This cast is pretty sketchy, as other error types can be thrown
// by parsingDidEnd!
return await sendErrorResponse(syntaxError as GraphQLError, SyntaxError);
}

@@ -305,3 +304,5 @@

} catch (err) {
return await sendErrorResponse(err);
// XXX: This cast is pretty sketchy, as other error types can be thrown
// by didResolveOperation!
return await sendErrorResponse(err as GraphQLError);
}

@@ -390,3 +391,3 @@

// they are of the wrong type. It also makes sure that all non-null
// variables are required and get non-null values. If any of these thingss
// variables are required and get non-null values. If any of these things
// lead to errors, we change them into UserInputError so that their code

@@ -435,4 +436,9 @@ // doesn't end up being INTERNAL_SERVER_ERROR, since these are client

} catch (executionError) {
await executionDispatcher.invokeHook('executionDidEnd', executionError);
return await sendErrorResponse(executionError);
await executionDispatcher.invokeHook(
'executionDidEnd',
executionError as Error,
);
// XXX: This cast is pretty sketchy, as other error types can be thrown
// in the try block!
return await sendErrorResponse(executionError as GraphQLError);
}

@@ -439,0 +445,0 @@ }

@@ -13,4 +13,4 @@ import { Request, Headers } from 'apollo-server-env';

} from './requestPipeline';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import {
import type { ApolloServerPlugin } from 'apollo-server-plugin-base';
import type {
WithRequired,

@@ -70,2 +70,6 @@ GraphQLExecutionResult,

export function isHttpQueryError(e: unknown): e is HttpQueryError {
return (e as any)?.name === 'HttpQueryError';
}
/**

@@ -115,2 +119,4 @@ * If options is specified, then the errors array will be formatted

const NODE_ENV = process.env.NODE_ENV ?? '';
export async function runHttpQuery(

@@ -120,3 +126,3 @@ handlerArguments: Array<any>,

): Promise<HttpQueryResponse> {
function debugFromNodeEnv(nodeEnv: string | undefined) {
function debugFromNodeEnv(nodeEnv: string = NODE_ENV) {
return nodeEnv !== 'production' && nodeEnv !== 'test';

@@ -132,5 +138,6 @@ }

// debug. Therefore, we need to do some unnatural things, such
// as use NODE_ENV to determine the debug settings
return throwHttpGraphQLError(500, [e], {
debug: debugFromNodeEnv(process.env.NODE_ENV),
// as use NODE_ENV to determine the debug settings. Please note that this
// will not be sensitive to any runtime changes made to NODE_ENV.
return throwHttpGraphQLError(500, [e as Error], {
debug: debugFromNodeEnv(),
});

@@ -140,7 +147,3 @@ }

if (options.debug === undefined) {
const nodeEnv =
'__testing_nodeEnv__' in options
? options.__testing_nodeEnv__
: process.env.NODE_ENV;
options.debug = debugFromNodeEnv(nodeEnv);
options.debug = debugFromNodeEnv(options.nodeEnv);
}

@@ -158,3 +161,5 @@

(options.context as () => never)();
} catch (e) {
} catch (e: any) {
// XXX `any` isn't ideal, but this is the easiest thing for now, without
// introducing a strong `instanceof GraphQLError` requirement.
e.message = `Context creation failed: ${e.message}`;

@@ -325,3 +330,3 @@ // For errors that are not internal, such as authentication, we

return {
errors: formatApolloErrors([error], options),
errors: formatApolloErrors([error as Error], options),
};

@@ -370,3 +375,3 @@ }

}
return throwHttpGraphQLError(500, [error], options);
return throwHttpGraphQLError(500, [error as Error], options);
}

@@ -373,0 +378,0 @@

@@ -21,3 +21,4 @@ import type { GraphQLSchema, DocumentNode, ParseOptions } from 'graphql';

export { KeyValueCache } from 'apollo-server-caching';
import type { KeyValueCache } from 'apollo-server-caching';
export type { KeyValueCache };

@@ -85,2 +86,4 @@ export type Context<T = object> = T;

export type DocumentStore = KeyValueCache<DocumentNode>;
// This configuration is shared between all integrations and should include

@@ -101,13 +104,6 @@ // fields that are not specific to a single integration

gateway?: GatewayInterface;
experimental_approximateDocumentStoreMiB?: number;
stopOnTerminationSignals?: boolean;
apollo?: ApolloConfigInput;
// Apollo Server only uses process.env.NODE_ENV to determine defaults for
// other behavior which have other mechanisms of setting explicitly. Sometimes
// our tests want to test the exact logic of how NODE_ENV affects defaults;
// they can set this parameter, but there's no reason to do so other than for
// tests. Note that an explicit `__testing_nodeEnv__: undefined` means "act as
// if the environment variable is not set", whereas the absence of
// `__testing_nodeEnv__` means to honor the environment variable.
__testing_nodeEnv__?: string | undefined;
nodeEnv?: string;
documentStore?: DocumentStore | null;
}

@@ -1,2 +0,2 @@

import { AnyFunction, AnyFunctionMap } from 'apollo-server-types';
import type { AnyFunction, AnyFunctionMap } from 'apollo-server-types';

@@ -3,0 +3,0 @@ type Args<F> = F extends (...args: infer A) => any ? A : never;

@@ -1,2 +0,2 @@

import {
import type {
CacheHint,

@@ -14,2 +14,3 @@ WithRequired,

GraphQLRequestContextValidationDidStart,
SchemaHash,
} from 'apollo-server-types';

@@ -21,3 +22,3 @@ import { GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql/type';

} from './schemaInstrumentation';
import {
import type {
ApolloServerPlugin,

@@ -29,3 +30,2 @@ GraphQLRequestExecutionListener,

import { Dispatcher } from './dispatcher';
import { generateSchemaHash } from './schemaHash';
import { getOperationAST, parse, validate as graphqlValidate } from 'graphql';

@@ -109,3 +109,2 @@ import { newCachePolicy } from '../cachePolicy';

const schemaHash = generateSchemaHash(schema);
let serverListener: GraphQLServerListener | undefined;

@@ -116,3 +115,3 @@ if (typeof pluginInstance.serverWillStart === 'function') {

schema,
schemaHash,
schemaHash: 'deprecated' as SchemaHash,
serverlessFramework: false,

@@ -134,3 +133,3 @@ apollo: {

schema,
schemaHash: generateSchemaHash(schema),
schemaHash: 'deprecated' as SchemaHash,
request: graphqlRequest,

@@ -284,3 +283,6 @@ metrics: Object.create(null),

} catch (executionErr) {
await executionDispatcher.invokeHook('executionDidEnd', executionErr);
await executionDispatcher.invokeHook(
'executionDidEnd',
executionErr as Error,
);
}

@@ -287,0 +289,0 @@

import { parse } from 'graphql/language';
import { execute, ExecutionResult } from 'graphql/execution';
import { getIntrospectionQuery, IntrospectionSchema } from 'graphql/utilities';
import { getIntrospectionQuery, IntrospectionQuery } from 'graphql/utilities';
import stableStringify from 'fast-json-stable-stringify';
import { GraphQLSchema } from 'graphql/type';
import type { GraphQLSchema } from 'graphql/type';
import createSHA from './createSHA';
import { SchemaHash } from 'apollo-server-types';
import type { SchemaHash } from 'apollo-server-types';
/*
* This function returns a not particularly stable schema hash derived from a
* GraphQLSchema object. It works by running the `graphql-js` default
* introspection query against the schema and taking a SHA of a JSON encoding of
* the result. It is dependent on the precise introspection query returned by
* `graphql-js` and some of the details of how that library returns its data, so
* upgrading `graphql-js` can change its value. It was created for use in
* apollo-server-plugin-operation-registry but it is no longer used there. It is
* *not* the same as the hash used in schema and usage reporting, which is just
* a hash of the schema SDL document.
*
* For backwards-compatibility reasons, it is still calculated and passed to all
* plugin hooks, but it is not a good idea to use it for anything.
*/
export function generateSchemaHash(schema: GraphQLSchema): SchemaHash {
const introspectionQuery = getIntrospectionQuery();
const documentAST = parse(introspectionQuery);
const result = execute(schema, documentAST) as ExecutionResult;
const document = parse(introspectionQuery);
const result = execute({
schema,
document,
}) as ExecutionResult<IntrospectionQuery>;

@@ -35,3 +52,3 @@ // If the execution of an introspection query results in a then-able, it

const introspectionSchema: IntrospectionSchema = result.data.__schema;
const introspectionSchema = result.data.__schema;

@@ -38,0 +55,0 @@ // It's important that we perform a deterministic stringification here

@@ -10,4 +10,4 @@ import {

import { defaultFieldResolver } from 'graphql/execution';
import { FieldNode } from 'graphql/language';
import { GraphQLRequestExecutionListener } from 'apollo-server-plugin-base';
import type { FieldNode } from 'graphql/language';
import type { GraphQLRequestExecutionListener } from 'apollo-server-plugin-base';
import type { GraphQLObjectResolver } from '@apollographql/apollo-tools';

@@ -116,3 +116,3 @@

if (typeof didResolveField === 'function') {
didResolveField(error);
didResolveField(error as Error);
}

@@ -119,0 +119,0 @@ throw error;

@@ -1,3 +0,3 @@

import { GraphQLSchema } from 'graphql';
import {
import type { GraphQLSchema } from 'graphql';
import type {
ApolloConfig,

@@ -8,4 +8,4 @@ GraphQLExecutor,

} from 'apollo-server-types';
import { GatewayInterface, Unsubscriber } from '../types';
import { SchemaDerivedData } from '../ApolloServer';
import type { GatewayInterface, Unsubscriber } from '../types';
import type { SchemaDerivedData } from '../ApolloServer';

@@ -50,2 +50,3 @@ type SchemaDerivedDataProvider = (

readonly apiSchema: GraphQLSchema;
readonly schemaDerivedData: SchemaDerivedData;
};

@@ -74,6 +75,7 @@

apiSchema: options.apiSchema,
// The caller of the constructor expects us to fail early if the schema
// given is invalid/has errors, so we call the provider here. We also
// pass the result to start(), as the provider can be expensive to call.
schemaDerivedData: options.schemaDerivedDataProvider(options.apiSchema),
};
// The caller of the constructor expects us to fail early if the schema
// given is invalid/has errors, so we call the provider here.
options.schemaDerivedDataProvider(options.apiSchema);
}

@@ -125,5 +127,8 @@ }

} else {
this.processSchemaLoadOrUpdateEvent({
apiSchema: this.modeSpecificState.apiSchema,
});
this.processSchemaLoadOrUpdateEvent(
{
apiSchema: this.modeSpecificState.apiSchema,
},
this.modeSpecificState.schemaDerivedData,
);
return null;

@@ -174,3 +179,5 @@ }

throw new Error(
`An error was thrown from an 'onSchemaLoadOrUpdate' listener: ${e.message}`,
`An error was thrown from an 'onSchemaLoadOrUpdate' listener: ${
(e as Error).message
}`,
);

@@ -215,7 +222,8 @@ }

schemaContext: GraphQLSchemaContext,
schemaDerivedData?: SchemaDerivedData,
): void {
if (!this.isStopped) {
this.schemaDerivedData = this.schemaDerivedDataProvider(
schemaContext.apiSchema,
);
this.schemaDerivedData =
schemaDerivedData ??
this.schemaDerivedDataProvider(schemaContext.apiSchema);
this.schemaContext = schemaContext;

@@ -222,0 +230,0 @@ this.onSchemaLoadOrUpdateListeners.forEach((listener) => {

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

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

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc