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

refactor: use Promise constructor to wrap builtin gzip #7229

Merged
merged 2 commits into from Dec 7, 2022

Conversation

dnalborczyk
Copy link
Contributor

@dnalborczyk dnalborczyk commented Dec 7, 2022

support for Cloudflare Workers

ref: #6034

@netlify
Copy link

netlify bot commented Dec 7, 2022

Deploy Preview for apollo-server-docs failed.

Built without sensitive environment variables

Name Link
🔨 Latest commit 0154317
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/63910c41d759780008ecd2c1

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 7, 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 0154317:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

@glasser
Copy link
Member

glasser commented Dec 7, 2022

I am happy to merge this change because there's nothing particularly negative about it and I trust you that it resolves the CF worker issue.

But it is hard for me to know as a maintainer what to avoid doing in the future — eg, the fact that zlib is fine for CF workers and utils is not seems unpredictable. If you have any thoughts on something straightforward we can add to our CI process to check that we're not breaking that, that would be awesome — I don't think you suggested anything specific on #6034 but I might have missed it.

@glasser glasser enabled auto-merge (squash) December 7, 2022 21:57
@glasser glasser merged commit d057e2f into apollographql:main Dec 7, 2022
glasser pushed a commit that referenced this pull request Dec 12, 2022
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @apollo/server-plugin-response-cache@4.1.0

### Minor Changes

- [#7241](#7241)
[`d7e9b9759`](d7e9b97)
Thanks [@glasser](https://github.com/glasser)! - If the cache you
provide to the `cache` option is created with
`PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation`
(new in `@apollo/utils.keyvaluecache@2.1.0`), the `fqc:` prefix will not
be added to cache keys.

## @apollo/server@4.3.0

### Minor Changes

- [#7241](#7241)
[`d7e9b9759`](d7e9b97)
Thanks [@glasser](https://github.com/glasser)! - If the cache you
provide to the `persistedQueries.cache` option is created with
`PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation`
(new in `@apollo/utils.keyvaluecache@2.1.0`), the `apq:` prefix will not
be added to cache keys. Providing such a cache to `new ApolloServer()`
throws an error.

### Patch Changes

- [#7232](#7232)
[`3a4823e0d`](3a4823e)
Thanks [@glasser](https://github.com/glasser)! - Refactor the
implementation of `ApolloServerPluginDrainHttpServer`'s grace period.
This is intended to be a no-op.

- [#7229](#7229)
[`d057e2ffc`](d057e2f)
Thanks [@dnalborczyk](https://github.com/dnalborczyk)! - Improve
compatibility with Cloudflare workers by avoiding the use of the Node
`util` package. This change is intended to be a no-op.

- [#7228](#7228)
[`f97e55304`](f97e553)
Thanks [@dnalborczyk](https://github.com/dnalborczyk)! - Improve
compatibility with Cloudflare workers by avoiding the use of the Node
`url` package. This change is intended to be a no-op.

- [#7241](#7241)
[`d7e9b9759`](d7e9b97)
Thanks [@glasser](https://github.com/glasser)! - For ease of upgrade
from the recommended configuration of Apollo Server v3.9+, you can now
pass `new ApolloServer({ cache: 'bounded' })`, which is equivalent to
not providing the `cache` option (as a bounded cache is now the default
in AS4).

## @apollo/server-integration-testsuite@4.3.0

### Patch Changes

- [#7228](#7228)
[`f97e55304`](f97e553)
Thanks [@dnalborczyk](https://github.com/dnalborczyk)! - Improve
compatibility with Cloudflare workers by avoiding the use of the Node
`url` package. This change is intended to be a no-op.

- Updated dependencies
\[[`3a4823e0d`](3a4823e),
[`d057e2ffc`](d057e2f),
[`f97e55304`](f97e553),
[`d7e9b9759`](d7e9b97),
[`d7e9b9759`](d7e9b97)]:
    -   @apollo/server@4.3.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@dnalborczyk dnalborczyk deleted the gzip/promise branch December 13, 2022 01:04
@dnalborczyk
Copy link
Contributor Author

thank you @glasser for pulling this in!

I am happy to merge this change because there's nothing particularly negative about it and I trust you that it resolves the CF worker issue.

But it is hard for me to know as a maintainer what to avoid doing in the future — eg, the fact that zlib is fine for CF workers and utils is not seems unpredictable.

I agree, that's totally understandable. Cloudflare Workers are implemented using the v8 engine (always latest as far as I understand) in addition to Web API (URL, URLSearchParams, URLPattern, TextEncoder etc.). Wrangler is the build and deployment tool for CFW. as of v2, they adopted esbuild as default bundler, for the fantastic performance, as CFW currently only supports a single file to be deployed. however developers can use any bundler (webpack, rollup, etc.). esbuild transforms js/ts, bundles, and minifies - but it doesn't know anything about any node specific built-ins (util, assert etc.) nor globals (Buffer, process etc.). Those can be, and are, polyfilled by plugins. if the plugins were up-to-date and fully working none of this would be a problem, unfortunately they are not, as esbuild is also a fairly new project.

If you have any thoughts on something straightforward we can add to our CI process to check that we're not breaking that, that would be awesome — I don't think you suggested anything specific on #6034 but I might have missed it.

Good point. There might be not a straight forward way to easily accomplish that without constraining further development and improvements of Apollo Server. Generally speaking, preferring JS/Web API over platform specific API would definitely help, for CFW or any other platform than node.js, such as deno, bun etc. In addition, avoiding (currently) non-polyfillable modules such as http, fs etc. would help as well.

I would think most developers who are using CFW are hopefully aware of the implications the platform comes with, and we could (or even should) add some additional suggestions on the the CFW integration docs, such as pinning the deps, and always use lock files etc., otherwise bring it up in an issue or a PR.

@glasser
Copy link
Member

glasser commented Dec 13, 2022

Thanks. I guess my question is: is there something pretty simple we can do in a smoke test perhaps using Wrangler directly that builds a minimal Apollo Server app and sees that it at least starts up properly (ie the imports don't fail)?

@dnalborczyk
Copy link
Contributor Author

dnalborczyk commented Dec 14, 2022

is there something pretty simple we can do in a smoke test perhaps using Wrangler directly that builds a minimal Apollo Server app and sees that it at least starts up properly (ie the imports don't fail)?

yes, there is! for local development wrangler is using miniflare under the hood, which is (or better has been) running on node.js, which probably wouldn't help much. miniflare v3 is switching from node.js to the open sourced workerd runtime, which itself is powering cloudflare workers, which should behave pretty much exactly as the published CFW version.

unfortunately, the problem is that the generated output and the behavior really depends on which tools and which versions are being used 😞

@glasser
Copy link
Member

glasser commented Dec 14, 2022

OK, so waiting til v3 might make sense for this sort of testing?

What's the next step we can take towards getting Cloudflare support on our integrations page? Your package ready for that?

@dnalborczyk
Copy link
Contributor Author

OK, so waiting til v3 might make sense for this sort of testing?

forgot to mention, wrangler v2 has support for an experimental-local flag, which then uses miniflare v3 powered by workerd. the last couple days I got everything working locally: CFW standalone as well as federation (gateway + subgraphs).

https://github.com/dnalborczyk/apollo-server-cloudflare-workers
https://github.com/dnalborczyk/apollo-federation-cloudflare-workers

npm start for local development, might not currently work with node v19 and/or npm v9. I haven't looked into the details.

What's the next step we can take towards getting Cloudflare support on our integrations page? Your package ready for that?

There's only a couple things left, other than that it should be ready to go, we can move the repo over to as integrations:

I removed the path and http method restriction dnalborczyk/apollo-server-integrations-cloudflare-workers@8859f7c because it did only support POST requests (no GET), and a path was required (should be optional). I want to re-introduce both again at a later time. (will be optional and non-breaking).

another small thing on my todo list is to look at: https://github.com/dnalborczyk/apollo-server-integrations-cloudflare-workers/blob/97c085d7e481a94d668a0b4378d7e9462a3e36d7/src/startServerAndCreateCloudflareWorkersHandler.ts#L97

last but not least we need to add some tests.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 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.

None yet

2 participants