Skip to content

Commit 9bd7748

Browse files
bnjjjtrevor-scheer
andauthored
Update subscription callback protocol to latest / GA (#7793)
Ref: [issue](apollographql/router#3884) --------- Signed-off-by: Benjamin Coenen <[email protected]> Co-authored-by: Trevor Scheer <[email protected]>
1 parent 2272841 commit 9bd7748

4 files changed

Lines changed: 921 additions & 708 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@apollo/server': patch
3+
---
4+
5+
General availability of subscription callback protocol

packages/server/src/ApolloServer.ts

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1+
import type { GatewayExecutor } from '@apollo/server-gateway-interface';
12
import { isNodeLike } from '@apollo/utils.isnodelike';
3+
import {
4+
InMemoryLRUCache,
5+
PrefixingKeyValueCache,
6+
type KeyValueCache,
7+
} from '@apollo/utils.keyvaluecache';
28
import type { Logger } from '@apollo/utils.logger';
9+
import type { WithRequired } from '@apollo/utils.withrequired';
310
import { makeExecutableSchema } from '@graphql-tools/schema';
411
import resolvable, { type Resolvable } from '@josephg/resolvable';
512
import {
13+
GraphQLError,
614
assertValidSchema,
15+
print,
16+
printSchema,
717
type DocumentNode,
8-
GraphQLError,
18+
type FormattedExecutionResult,
919
type GraphQLFieldResolver,
1020
type GraphQLFormattedError,
1121
type GraphQLSchema,
1222
type ParseOptions,
13-
print,
14-
printSchema,
1523
type TypedQueryDocumentNode,
1624
type ValidationContext,
1725
type ValidationRule,
18-
type FormattedExecutionResult,
1926
} from 'graphql';
20-
import {
21-
type KeyValueCache,
22-
InMemoryLRUCache,
23-
PrefixingKeyValueCache,
24-
} from '@apollo/utils.keyvaluecache';
2527
import loglevel from 'loglevel';
2628
import Negotiator from 'negotiator';
2729
import { newCachePolicy } from './cachePolicy.js';
@@ -35,45 +37,43 @@ import {
3537
ApolloServerErrorCode,
3638
ApolloServerValidationErrorCode,
3739
} from './errors/index.js';
40+
import type { ApolloServerOptionsWithStaticSchema } from './externalTypes/constructor.js';
3841
import type {
42+
ExecuteOperationOptions,
43+
VariableValues,
44+
} from './externalTypes/graphql.js';
45+
import type {
46+
ApolloConfig,
47+
ApolloServerOptions,
3948
ApolloServerPlugin,
4049
BaseContext,
50+
ContextThunk,
51+
DocumentStore,
4152
GraphQLRequest,
53+
GraphQLRequestContext,
4254
GraphQLResponse,
43-
GraphQLServerListener,
4455
GraphQLServerContext,
56+
GraphQLServerListener,
57+
HTTPGraphQLHead,
4558
HTTPGraphQLRequest,
4659
HTTPGraphQLResponse,
4760
LandingPage,
48-
ApolloConfig,
49-
ApolloServerOptions,
50-
DocumentStore,
5161
PersistedQueryOptions,
52-
ContextThunk,
53-
GraphQLRequestContext,
54-
HTTPGraphQLHead,
5562
} from './externalTypes/index.js';
5663
import { runPotentiallyBatchedHttpQuery } from './httpBatching.js';
57-
import { type InternalPluginId, pluginIsInternal } from './internalPlugin.js';
64+
import type { GraphQLExperimentalIncrementalExecutionResults } from './incrementalDeliveryPolyfill.js';
65+
import { pluginIsInternal, type InternalPluginId } from './internalPlugin.js';
5866
import {
5967
preventCsrf,
6068
recommendedCsrfPreventionRequestHeaders,
6169
} from './preventCsrf.js';
6270
import { APQ_CACHE_PREFIX, processGraphQLRequest } from './requestPipeline.js';
6371
import { newHTTPGraphQLHead, prettyJSONStringify } from './runHttpQuery.js';
64-
import { SchemaManager } from './utils/schemaManager.js';
65-
import { isDefined } from './utils/isDefined.js';
72+
import { HeaderMap } from './utils/HeaderMap.js';
6673
import { UnreachableCaseError } from './utils/UnreachableCaseError.js';
6774
import { computeCoreSchemaHash } from './utils/computeCoreSchemaHash.js';
68-
import type { WithRequired } from '@apollo/utils.withrequired';
69-
import type { ApolloServerOptionsWithStaticSchema } from './externalTypes/constructor.js';
70-
import type { GatewayExecutor } from '@apollo/server-gateway-interface';
71-
import type { GraphQLExperimentalIncrementalExecutionResults } from './incrementalDeliveryPolyfill.js';
72-
import { HeaderMap } from './utils/HeaderMap.js';
73-
import type {
74-
ExecuteOperationOptions,
75-
VariableValues,
76-
} from './externalTypes/graphql.js';
75+
import { isDefined } from './utils/isDefined.js';
76+
import { SchemaManager } from './utils/schemaManager.js';
7777

7878
const NoIntrospection: ValidationRule = (context: ValidationContext) => ({
7979
Field(node) {
@@ -1354,6 +1354,8 @@ export function isImplicitlyInstallablePlugin<TContext extends BaseContext>(
13541354

13551355
export const MEDIA_TYPES = {
13561356
APPLICATION_JSON: 'application/json; charset=utf-8',
1357+
APPLICATION_JSON_GRAPHQL_CALLBACK:
1358+
'application/json; callbackSpec=1.0; charset=utf-8',
13571359
APPLICATION_GRAPHQL_RESPONSE_JSON:
13581360
'application/graphql-response+json; charset=utf-8',
13591361
// We do *not* currently support this content-type; we will once incremental
@@ -1378,6 +1380,7 @@ export function chooseContentTypeForSingleResultResponse(
13781380
}).mediaType([
13791381
MEDIA_TYPES.APPLICATION_JSON,
13801382
MEDIA_TYPES.APPLICATION_GRAPHQL_RESPONSE_JSON,
1383+
MEDIA_TYPES.APPLICATION_JSON_GRAPHQL_CALLBACK,
13811384
]);
13821385
if (preferred) {
13831386
return preferred;

0 commit comments

Comments
 (0)