Skip to content

Commit

Permalink
Update subscription callback protocol to latest / GA (#7793)
Browse files Browse the repository at this point in the history
Ref:
[issue](apollographql/router#3884)
---------

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>
  • Loading branch information
bnjjj and trevor-scheer committed Dec 18, 2023
1 parent 2272841 commit 9bd7748
Show file tree
Hide file tree
Showing 4 changed files with 921 additions and 708 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-gorillas-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/server': patch
---

General availability of subscription callback protocol
59 changes: 31 additions & 28 deletions packages/server/src/ApolloServer.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import type { GatewayExecutor } from '@apollo/server-gateway-interface';
import { isNodeLike } from '@apollo/utils.isnodelike';
import {
InMemoryLRUCache,
PrefixingKeyValueCache,
type KeyValueCache,
} from '@apollo/utils.keyvaluecache';
import type { Logger } from '@apollo/utils.logger';
import type { WithRequired } from '@apollo/utils.withrequired';
import { makeExecutableSchema } from '@graphql-tools/schema';
import resolvable, { type Resolvable } from '@josephg/resolvable';
import {
GraphQLError,
assertValidSchema,
print,
printSchema,
type DocumentNode,
GraphQLError,
type FormattedExecutionResult,
type GraphQLFieldResolver,
type GraphQLFormattedError,
type GraphQLSchema,
type ParseOptions,
print,
printSchema,
type TypedQueryDocumentNode,
type ValidationContext,
type ValidationRule,
type FormattedExecutionResult,
} from 'graphql';
import {
type KeyValueCache,
InMemoryLRUCache,
PrefixingKeyValueCache,
} from '@apollo/utils.keyvaluecache';
import loglevel from 'loglevel';
import Negotiator from 'negotiator';
import { newCachePolicy } from './cachePolicy.js';
Expand All @@ -35,45 +37,43 @@ import {
ApolloServerErrorCode,
ApolloServerValidationErrorCode,
} from './errors/index.js';
import type { ApolloServerOptionsWithStaticSchema } from './externalTypes/constructor.js';
import type {
ExecuteOperationOptions,
VariableValues,
} from './externalTypes/graphql.js';
import type {
ApolloConfig,
ApolloServerOptions,
ApolloServerPlugin,
BaseContext,
ContextThunk,
DocumentStore,
GraphQLRequest,
GraphQLRequestContext,
GraphQLResponse,
GraphQLServerListener,
GraphQLServerContext,
GraphQLServerListener,
HTTPGraphQLHead,
HTTPGraphQLRequest,
HTTPGraphQLResponse,
LandingPage,
ApolloConfig,
ApolloServerOptions,
DocumentStore,
PersistedQueryOptions,
ContextThunk,
GraphQLRequestContext,
HTTPGraphQLHead,
} from './externalTypes/index.js';
import { runPotentiallyBatchedHttpQuery } from './httpBatching.js';
import { type InternalPluginId, pluginIsInternal } from './internalPlugin.js';
import type { GraphQLExperimentalIncrementalExecutionResults } from './incrementalDeliveryPolyfill.js';
import { pluginIsInternal, type InternalPluginId } from './internalPlugin.js';
import {
preventCsrf,
recommendedCsrfPreventionRequestHeaders,
} from './preventCsrf.js';
import { APQ_CACHE_PREFIX, processGraphQLRequest } from './requestPipeline.js';
import { newHTTPGraphQLHead, prettyJSONStringify } from './runHttpQuery.js';
import { SchemaManager } from './utils/schemaManager.js';
import { isDefined } from './utils/isDefined.js';
import { HeaderMap } from './utils/HeaderMap.js';
import { UnreachableCaseError } from './utils/UnreachableCaseError.js';
import { computeCoreSchemaHash } from './utils/computeCoreSchemaHash.js';
import type { WithRequired } from '@apollo/utils.withrequired';
import type { ApolloServerOptionsWithStaticSchema } from './externalTypes/constructor.js';
import type { GatewayExecutor } from '@apollo/server-gateway-interface';
import type { GraphQLExperimentalIncrementalExecutionResults } from './incrementalDeliveryPolyfill.js';
import { HeaderMap } from './utils/HeaderMap.js';
import type {
ExecuteOperationOptions,
VariableValues,
} from './externalTypes/graphql.js';
import { isDefined } from './utils/isDefined.js';
import { SchemaManager } from './utils/schemaManager.js';

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

export const MEDIA_TYPES = {
APPLICATION_JSON: 'application/json; charset=utf-8',
APPLICATION_JSON_GRAPHQL_CALLBACK:
'application/json; callbackSpec=1.0; charset=utf-8',
APPLICATION_GRAPHQL_RESPONSE_JSON:
'application/graphql-response+json; charset=utf-8',
// We do *not* currently support this content-type; we will once incremental
Expand All @@ -1378,6 +1380,7 @@ export function chooseContentTypeForSingleResultResponse(
}).mediaType([
MEDIA_TYPES.APPLICATION_JSON,
MEDIA_TYPES.APPLICATION_GRAPHQL_RESPONSE_JSON,
MEDIA_TYPES.APPLICATION_JSON_GRAPHQL_CALLBACK,
]);
if (preferred) {
return preferred;
Expand Down
Loading

0 comments on commit 9bd7748

Please sign in to comment.