Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gateway support via new @apollo/server-gateway-interface package #6771

Merged
merged 5 commits into from
Aug 8, 2022

Conversation

glasser
Copy link
Member

@glasser glasser commented Aug 5, 2022

Until now, the refactored AS4 did not support Apollo Gateway (or any
implementation of the AS3 gateway option). That's because
GraphQLRequestContext is part of the API between Apollo Gateway and
Apollo Server, and that type has changed in some minor but incompatible
ways in AS4.

(Additionally, clashes between declare module declarations in AS3 and
AS4 caused issue, but we removed those declarations from this branch in
PRs #6764 and #6759.)

This commit restores gateway support. It does this by having AS4 produce
an AS3-style request context object. It uses a new
@apollo/server-gateway-interface package to define the appropriate
types for connecting to Gateway.

(Note: this package will be code reviewed in this PR in this repo, but
once it's approved, it will move to the apollo-utils repo and be
released as non-alpha there. Once we've released AS4.0.0 we can move
that package back here, but trying to do some prereleases and some
non-prereleases on the same branch seems challenging.)

This PR removes the top-level executor function, which is redundant
with the gateway option. (Internally, the relevant field is now named
gatewayExecutor.)

Some types had been parametrized by TContext, because in AS3,
GraphQLExecutor (now GatewayExecutor) appeared to take a
<TContext>. However, even though the type itself took a generic
argument, its main use in the return from gateway.load implicitly
hardcoded the default TContext. So we are doubling down on that and
only allowing GraphQLExecutor to use AS3's default TContext, the
quite flexible Record<string, any>.

Most of the way toward #6719.

@changeset-bot
Copy link

changeset-bot bot commented Aug 5, 2022

🦋 Changeset detected

Latest commit: 94f8439

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@apollo/server-integration-testsuite Patch
@apollo/server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Aug 5, 2022

Deploy Preview for apollo-server-docs ready!

Name Link
🔨 Latest commit 94f8439
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/62f198c68284a200090268ca
😎 Deploy Preview https://deploy-preview-6771--apollo-server-docs.netlify.app/migration
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@glasser glasser changed the base branch from main to version-4 August 5, 2022 23:24
@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 5, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 94f8439:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

Until now, the refactored AS4 did not support Apollo Gateway (or any
implementation of the AS3 `gateway` option). That's because
`GraphQLRequestContext` is part of the API between Apollo Gateway and
Apollo Server, and that type has changed in some minor but incompatible
ways in AS4.

(Additionally, clashes between `declare module` declarations in AS3 and
AS4 caused issue, but we removed those declarations from this branch in
PRs #6764 and #6759.)

This commit restores gateway support. It does this by having AS4 produce
an AS3-style request context object. It uses a new
`@apollo/server-gateway-interface` package to define the appropriate
types for connecting to Gateway.

(Note: this package will be code reviewed in this PR in this repo, but
once it's approved, it will move to the apollo-utils repo and be
released as non-alpha there. Once we've released AS4.0.0 we can move
that package back here, but trying to do some prereleases and some
non-prereleases on the same branch seems challenging.)

This PR removes the top-level `executor` function, which is redundant
with the `gateway` option. (Internally, the relevant field is now named
`gatewayExecutor`.)

Some types had been parametrized by `TContext`, because in AS3,
`GraphQLExecutor` (now `GatewayExecutor`) appeared to take a
`<TContext>`. However, even though the type itself took a generic
argument, its main use in the return from `gateway.load` implicitly
hardcoded the default `TContext`. So we are doubling down on that and
only allowing `GraphQLExecutor` to use AS3's default `TContext`, the
quite flexible `Record<string, any>`.

Most of the way toward #6719.
@glasser glasser force-pushed the glasser/separate-gateway-interface-package branch from 80e8f81 to 8a6ee4a Compare August 8, 2022 20:59
@glasser glasser changed the title Glasser/separate gateway interface package Gateway support via new @apollo/server-gateway-interface package Aug 8, 2022
docs/source/migration.mdx Outdated Show resolved Hide resolved
"name": "@apollo/server-gateway-interface",
"version": "0.0.0",
"description": "Interface used to connect Apollo Gateway to Apollo Server",
"type": "module",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop this given no runtime?

Suggested change
"type": "module",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that TSC doesn't look at this field? I guess that's just a nodenext thing? Do you think it hurts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair question. I don't think it hurts, and I can't say for sure about nodenext so I don't mind if you leave it.

status?: number;
}

export interface GatewayHTTPHeaders {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be a re-export of FetcherHeaders?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, nice, I think you're right. FetcherHeaders also has extends Iterable<[string, string]> but that shouldn't hurt.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Request and Response are intentionally smaller though, but you didn't suggest that :) )

glasser and others added 3 commits August 8, 2022 15:09
Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>
Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>
glasser added a commit to apollographql/apollo-utils that referenced this pull request Aug 8, 2022
glasser added a commit to apollographql/apollo-utils that referenced this pull request Aug 8, 2022
glasser added a commit to apollographql/apollo-utils that referenced this pull request Aug 8, 2022
@glasser glasser marked this pull request as ready for review August 8, 2022 23:15
@glasser
Copy link
Member Author

glasser commented Aug 8, 2022

Trevor said it would be fine to merge (and he's about to be out for a week)

@glasser glasser merged commit bce9150 into version-4 Aug 8, 2022
@glasser glasser deleted the glasser/separate-gateway-interface-package branch August 8, 2022 23:57
@github-actions github-actions bot mentioned this pull request Oct 10, 2022
trevor-scheer pushed a commit that referenced this pull request Oct 17, 2022
trevor-scheer pushed a commit that referenced this pull request Oct 17, 2022
trevor-scheer pushed a commit that referenced this pull request Oct 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants