apollo-server icon indicating copy to clipboard operation
apollo-server copied to clipboard

Make it possible to use AS4 with Apollo Gateway

Open glasser opened this issue 3 years ago • 2 comments
trafficstars

Right now, you can't combine AS4 with any released version of Apollo Gateway. This is for a combination of runtime and compile time reasons.

The runtime reason is that the executor function returned by AG takes an AS3 GraphQLRequestContext, not an AS4 one.

The compile time reason is that Gateway has dependencies on AS3 code and the two declare module declarations in AS4 conflict with the AS3 versions.

I suspect the best fix for the compile time issue is to just break the dependency via #6057.

My current theory about the best fix for the runtime reason is just to have some code that converts an AS4 GraphQLRequestContext into an AS3-style one, and leave it there indefinitely (since Gateway is somewhat terminal to be replaced by Router anyway).

glasser avatar Jul 22 '22 17:07 glasser

Strategy:

  • Create a new package in this repo like @apollo/gateway-interface. This is a pure types package that defines essentially the AS3 API to Gateway (with the v0.35.0 constraints we've already made of assuming onSchemaLoadOrWhatever exists). Ideally this is defined purely in terms of basic TS types and graphql. There are a few bits that depend on apollo-server-env so we may need to just copy that file into this package too (because @types/node-fetch and @apollo/utils.fetcher are probably not compatible enough, though we can try).
  • Change Gateway itself to use these type definitions (perhaps just an alpha) instead of depending on AS3. (Also switch apollo-reporting-protobuf to @apollo/usage-reporting-protobuf, which seems to be completely drop-in.)
  • Make other changes to completely drop dependency on AS3 from Gateway (eg use GraphQLError directly instead of ApolloError and its subclasses), switch away from apollo-server-caching for an internal use, figure out what's going on with enablePluginsForSchemaResolvers in LocalGraphQLDataSource (is this just for testing? is it still needed or was it part of enabling __resolveObject in tests which we've removed?).
  • Publish this dep-free gateway to v0 and v2.
  • Change v4 AS to use the new gateway interface package and to have a little shim to change its GraphQLRequestContext into the old version.
  • Require the latest versions of Gateway, at least if you're using TypeScript; if you're using JS you might be able to get away with v0.35.0 since most of these other changes are TS-specific.

glasser avatar Jul 22 '22 18:07 glasser

Note: also remove the compile-time dependency of @apollo/subgraph on apollo-server-types (which isn't even in the monorepo dev dependencies) that is used for CacheHint. Maybe via a new cache control package that lets us entirely drop the declare module?

glasser avatar Aug 02 '22 17:08 glasser