initial update

This commit is contained in:
jackbeeby
2025-05-15 13:32:55 +10:00
commit 7b07a49fbe
4412 changed files with 909535 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
# Apollo Server/Gateway interface
This package defines TypeScript types for the interface between Apollo Server and Apollo Gateway. It contains no runtime code.
The types in this package describe the API as of Gateway 0.35.0 (ie, with onSchemaLoadOrUpdate). It is extracted from the Apollo Server 3 `apollo-server-types` package. Most of the type names have been changed to start with `Gateway`, so that they coexist better with similarly-named types. (Because TypeScript is generally structurally typed, this is OK.)
Note that the cache scope field (eg, on `requestContext.overallCachePolicy.scope`) is defined as `any` in this package. That's because in AS3 this type is an enum, and enums in TypeScript are _not_ structurally typed. So we can't actually create an object of this type without depending on AS3 (or updating AS3 to get its definition from somewhere shared).
We have updated `@apollo/gateway` (v0 and v2) to define its types from this package rather than `apollo-server-types`. This allows Gateway to be compatible with both AS3 and AS4 (and even AS2, for Gateway 0.x) without needing to pull either package's code into the TypeScript build.
Apollo Server 4 directly depends on this package and uses its types to construct its calls to the Gateway.

View File

@@ -0,0 +1,96 @@
import type { KeyValueCache } from '@apollo/utils.keyvaluecache';
import type { DocumentNode, ExecutionResult, GraphQLError, GraphQLFormattedError, GraphQLSchema, OperationDefinitionNode } from 'graphql';
import type { Logger } from '@apollo/utils.logger';
import type { Trace } from '@apollo/usage-reporting-protobuf';
import type { FetcherHeaders } from '@apollo/utils.fetcher';
export interface GatewayInterface {
onSchemaLoadOrUpdate(callback: GatewaySchemaLoadOrUpdateCallback): GatewayUnsubscriber;
load(options: {
apollo: GatewayApolloConfig;
}): Promise<GatewayLoadResult>;
stop(): Promise<void>;
}
export type GatewaySchemaLoadOrUpdateCallback = (schemaContext: {
apiSchema: GraphQLSchema;
coreSupergraphSdl: string;
}) => void;
export type GatewayUnsubscriber = () => void;
export interface GatewayApolloConfig {
key?: string;
keyHash?: string;
graphRef?: string;
}
export interface GatewayLoadResult {
executor: GatewayExecutor | null;
}
export type GatewayExecutor = (requestContext: GatewayGraphQLRequestContext) => Promise<GatewayExecutionResult>;
export type GatewayExecutionResult = ExecutionResult<Record<string, any>, Record<string, any>>;
export interface GatewayGraphQLRequestContext<TContext = Record<string, any>> {
readonly request: GatewayGraphQLRequest;
readonly response?: GatewayGraphQLResponse;
logger: Logger;
readonly schema: GraphQLSchema;
readonly schemaHash: GatewaySchemaHash;
readonly context: TContext;
readonly cache: KeyValueCache;
readonly queryHash: string;
readonly document: DocumentNode;
readonly source: string;
readonly operationName: string | null;
readonly operation: OperationDefinitionNode;
readonly errors?: ReadonlyArray<GraphQLError>;
readonly metrics: GatewayGraphQLRequestMetrics;
debug?: boolean;
readonly overallCachePolicy: any;
readonly requestIsBatched?: boolean;
}
export interface GatewayGraphQLRequest {
query?: string;
operationName?: string;
variables?: Record<string, any>;
extensions?: Record<string, any>;
http?: GatewayHTTPRequest;
}
export interface GatewayHTTPRequest {
readonly method: string;
readonly url: string;
readonly headers: FetcherHeaders;
}
export interface GatewayGraphQLResponse {
data?: Record<string, any> | null;
errors?: ReadonlyArray<GraphQLFormattedError>;
extensions?: Record<string, any>;
http?: GatewayHTTPResponse;
}
export interface GatewayHTTPResponse {
readonly headers: FetcherHeaders;
status?: number;
}
export type GatewaySchemaHash = string & {
__fauxpaque: 'SchemaHash';
};
export interface NonFtv1ErrorPath {
subgraph: string;
path: GraphQLError['path'];
}
export interface GatewayGraphQLRequestMetrics {
captureTraces?: boolean;
persistedQueryHit?: boolean;
persistedQueryRegister?: boolean;
responseCacheHit?: boolean;
forbiddenOperation?: boolean;
registeredOperation?: boolean;
startHrTime?: [number, number];
queryPlanTrace?: Trace.QueryPlanNode;
nonFtv1ErrorPaths?: NonFtv1ErrorPath[];
}
export interface GatewayCachePolicy extends GatewayCacheHint {
replace(hint: GatewayCacheHint): void;
restrict(hint: GatewayCacheHint): void;
policyIfCacheable(): Required<GatewayCacheHint> | null;
}
export interface GatewayCacheHint {
maxAge?: number;
scope?: any;
}
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +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AE,gBAAgB,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACvC,iBAAiB,IAAI,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC;CACxD;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAOhB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb"}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1 @@
{"type":"commonjs"}

View File

@@ -0,0 +1,96 @@
import type { KeyValueCache } from '@apollo/utils.keyvaluecache';
import type { DocumentNode, ExecutionResult, GraphQLError, GraphQLFormattedError, GraphQLSchema, OperationDefinitionNode } from 'graphql';
import type { Logger } from '@apollo/utils.logger';
import type { Trace } from '@apollo/usage-reporting-protobuf';
import type { FetcherHeaders } from '@apollo/utils.fetcher';
export interface GatewayInterface {
onSchemaLoadOrUpdate(callback: GatewaySchemaLoadOrUpdateCallback): GatewayUnsubscriber;
load(options: {
apollo: GatewayApolloConfig;
}): Promise<GatewayLoadResult>;
stop(): Promise<void>;
}
export type GatewaySchemaLoadOrUpdateCallback = (schemaContext: {
apiSchema: GraphQLSchema;
coreSupergraphSdl: string;
}) => void;
export type GatewayUnsubscriber = () => void;
export interface GatewayApolloConfig {
key?: string;
keyHash?: string;
graphRef?: string;
}
export interface GatewayLoadResult {
executor: GatewayExecutor | null;
}
export type GatewayExecutor = (requestContext: GatewayGraphQLRequestContext) => Promise<GatewayExecutionResult>;
export type GatewayExecutionResult = ExecutionResult<Record<string, any>, Record<string, any>>;
export interface GatewayGraphQLRequestContext<TContext = Record<string, any>> {
readonly request: GatewayGraphQLRequest;
readonly response?: GatewayGraphQLResponse;
logger: Logger;
readonly schema: GraphQLSchema;
readonly schemaHash: GatewaySchemaHash;
readonly context: TContext;
readonly cache: KeyValueCache;
readonly queryHash: string;
readonly document: DocumentNode;
readonly source: string;
readonly operationName: string | null;
readonly operation: OperationDefinitionNode;
readonly errors?: ReadonlyArray<GraphQLError>;
readonly metrics: GatewayGraphQLRequestMetrics;
debug?: boolean;
readonly overallCachePolicy: any;
readonly requestIsBatched?: boolean;
}
export interface GatewayGraphQLRequest {
query?: string;
operationName?: string;
variables?: Record<string, any>;
extensions?: Record<string, any>;
http?: GatewayHTTPRequest;
}
export interface GatewayHTTPRequest {
readonly method: string;
readonly url: string;
readonly headers: FetcherHeaders;
}
export interface GatewayGraphQLResponse {
data?: Record<string, any> | null;
errors?: ReadonlyArray<GraphQLFormattedError>;
extensions?: Record<string, any>;
http?: GatewayHTTPResponse;
}
export interface GatewayHTTPResponse {
readonly headers: FetcherHeaders;
status?: number;
}
export type GatewaySchemaHash = string & {
__fauxpaque: 'SchemaHash';
};
export interface NonFtv1ErrorPath {
subgraph: string;
path: GraphQLError['path'];
}
export interface GatewayGraphQLRequestMetrics {
captureTraces?: boolean;
persistedQueryHit?: boolean;
persistedQueryRegister?: boolean;
responseCacheHit?: boolean;
forbiddenOperation?: boolean;
registeredOperation?: boolean;
startHrTime?: [number, number];
queryPlanTrace?: Trace.QueryPlanNode;
nonFtv1ErrorPaths?: NonFtv1ErrorPath[];
}
export interface GatewayCachePolicy extends GatewayCacheHint {
replace(hint: GatewayCacheHint): void;
restrict(hint: GatewayCacheHint): void;
policyIfCacheable(): Required<GatewayCacheHint> | null;
}
export interface GatewayCacheHint {
maxAge?: number;
scope?: any;
}
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,YAAY,EAC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BAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAOhB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb"}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1 @@
{"type":"module"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,40 @@
{
"name": "@apollo/server-gateway-interface",
"version": "1.1.1",
"description": "Interface used to connect Apollo Gateway to Apollo Server",
"type": "module",
"main": "",
"types": "dist/esm/index.d.ts",
"exports": {
".": {
"types": {
"require": "./dist/cjs/index.d.ts",
"default": "./dist/esm/index.d.ts"
}
}
},
"repository": {
"type": "git",
"url": "https://github.com/apollographql/apollo-server",
"directory": "packages/gateway-interface"
},
"keywords": [],
"author": "Apollo <packages@apollographql.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/apollographql/apollo-server/issues"
},
"homepage": "https://github.com/apollographql/apollo-server#readme",
"dependencies": {
"@apollo/utils.fetcher": "^2.0.0",
"@apollo/utils.logger": "^2.0.0",
"@apollo/utils.keyvaluecache": "^2.1.0",
"@apollo/usage-reporting-protobuf": "^4.1.1"
},
"peerDependencies": {
"graphql": "14.x || 15.x || 16.x"
},
"volta": {
"extends": "../../package.json"
}
}

View File

@@ -0,0 +1,139 @@
import type { KeyValueCache } from '@apollo/utils.keyvaluecache';
import type {
DocumentNode,
ExecutionResult,
GraphQLError,
GraphQLFormattedError,
GraphQLSchema,
OperationDefinitionNode,
} from 'graphql';
import type { Logger } from '@apollo/utils.logger';
import type { Trace } from '@apollo/usage-reporting-protobuf';
import type { FetcherHeaders } from '@apollo/utils.fetcher';
export interface GatewayInterface {
onSchemaLoadOrUpdate(
callback: GatewaySchemaLoadOrUpdateCallback,
): GatewayUnsubscriber;
load(options: { apollo: GatewayApolloConfig }): Promise<GatewayLoadResult>;
stop(): Promise<void>;
}
export type GatewaySchemaLoadOrUpdateCallback = (schemaContext: {
apiSchema: GraphQLSchema;
coreSupergraphSdl: string;
}) => void;
export type GatewayUnsubscriber = () => void;
export interface GatewayApolloConfig {
key?: string;
keyHash?: string;
graphRef?: string;
}
export interface GatewayLoadResult {
executor: GatewayExecutor | null;
}
export type GatewayExecutor = (
requestContext: GatewayGraphQLRequestContext,
) => Promise<GatewayExecutionResult>;
export type GatewayExecutionResult = ExecutionResult<
Record<string, any>,
Record<string, any>
>;
// Note that the default value for TContext is the same as in AS3, not
// BaseContext.
export interface GatewayGraphQLRequestContext<TContext = Record<string, any>> {
readonly request: GatewayGraphQLRequest;
readonly response?: GatewayGraphQLResponse;
logger: Logger;
readonly schema: GraphQLSchema;
readonly schemaHash: GatewaySchemaHash;
readonly context: TContext;
readonly cache: KeyValueCache;
readonly queryHash: string;
readonly document: DocumentNode;
readonly source: string;
readonly operationName: string | null;
readonly operation: OperationDefinitionNode;
readonly errors?: ReadonlyArray<GraphQLError>;
readonly metrics: GatewayGraphQLRequestMetrics;
debug?: boolean;
// In AS3 and AS4, this field is always set and is a GatewayCachePolicy, but
// in AS2 it is not always set and is only a GatewayCacheHint. We can't just
// declare this as `readonly overallCachePolicy?: GatewayCachePolicy |
// GatewayCacheHint` because then older versions of Gateway built against AS3
// types will fail to build. Gateway's own code always probes this field at
// runtime before using it anyway, so let's just make everything build by
// declaring this as `any`.
readonly overallCachePolicy: any;
// This was only added in v3.11/v4.1, so we don't want to declare that it's
// required. (In fact, we made it optional in v3.11.1 for this very reason.)
readonly requestIsBatched?: boolean;
}
export interface GatewayGraphQLRequest {
query?: string;
operationName?: string;
variables?: Record<string, any>;
extensions?: Record<string, any>;
http?: GatewayHTTPRequest;
}
export interface GatewayHTTPRequest {
readonly method: string;
readonly url: string;
readonly headers: FetcherHeaders;
}
export interface GatewayGraphQLResponse {
data?: Record<string, any> | null;
errors?: ReadonlyArray<GraphQLFormattedError>;
extensions?: Record<string, any>;
http?: GatewayHTTPResponse;
}
export interface GatewayHTTPResponse {
readonly headers: FetcherHeaders;
status?: number;
}
export type GatewaySchemaHash = string & { __fauxpaque: 'SchemaHash' };
export interface NonFtv1ErrorPath {
subgraph: string;
path: GraphQLError['path'];
}
export interface GatewayGraphQLRequestMetrics {
captureTraces?: boolean;
persistedQueryHit?: boolean;
persistedQueryRegister?: boolean;
responseCacheHit?: boolean;
forbiddenOperation?: boolean;
registeredOperation?: boolean;
startHrTime?: [number, number];
queryPlanTrace?: Trace.QueryPlanNode;
nonFtv1ErrorPaths?: NonFtv1ErrorPath[];
}
export interface GatewayCachePolicy extends GatewayCacheHint {
replace(hint: GatewayCacheHint): void;
restrict(hint: GatewayCacheHint): void;
policyIfCacheable(): Required<GatewayCacheHint> | null;
}
export interface GatewayCacheHint {
maxAge?: number;
// In AS3, this field is an enum. In TypeScript, enums are not structurally
// typed: you need to actually refer directly to the enum's definition to
// produce a value of its type in a typesafe way. Doing that would prevent us
// from severing the dependency on apollo-server-types (AS3), so instead we
// just use 'any'. The legal runtime values of this fields are the strings
// `PUBLIC` and `PRIVATE`.
scope?: any;
}