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

Inline usage reporting protobuf into main package #6515

Merged
merged 2 commits into from Jun 3, 2022

Conversation

glasser
Copy link
Member

@glasser glasser commented Jun 3, 2022

Keeping it separate mostly just means we have to worry about version
skew. It doesn't let us avoid the protobufjs dependency (it was just
transitive). Other packages that may need these types (like
@apollo/gateway) will have a peer dependency on @apollo/server
anyway.

Note that this package consists of .js and .d.ts files that are not
generated from .ts files, so they exist outside of src. We ensure they
end up in the published package via a change to .npmignore.

As before, the only code that can import the protobuf code should be
tests, import types, or code under src/plugin that is only evaluated
if the plugin is actually used.

Also fixes missing dependencies on cors and body-parser needed for
the standalone server. (As part of #6243 we may make sure that these are
only needed if you actually import the standalone server directory.)

Fixes #6510.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 3, 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 b15bc2c:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

@glasser glasser force-pushed the glasser/inline-usage-reporting-protobuf branch from da39ff4 to 3a5e303 Compare June 3, 2022 01:28
Keeping it separate mostly just means we have to worry about version
skew. It doesn't let us avoid the protobufjs dependency (it was just
transitive). Other packages that may need these types (like
`@apollo/gateway`) will have a peer dependency on `@apollo/server`
anyway.

Note that this package consists of .js and .d.ts files that are not
generated from .ts files, so they exist outside of `src`. We ensure they
end up in the published package via a change to `.npmignore`.

As before, the only code that can import the protobuf code should be
tests, `import type`s, or code under `src/plugin` that is only evaluated
if the plugin is actually used.

Fixes #6510.
@glasser glasser force-pushed the glasser/inline-usage-reporting-protobuf branch from 3a5e303 to b15bc2c Compare June 3, 2022 17:16
@glasser glasser merged commit 0b58585 into version-4 Jun 3, 2022
@glasser glasser deleted the glasser/inline-usage-reporting-protobuf branch June 3, 2022 17:35
glasser added a commit that referenced this pull request Jun 10, 2022
This reverts commit 0b58585.

This leaves the fix of adding cors and body-parser to server's deps and
leaves the removal of a TODO(AS4) about this.

The build process for this package is completely different from a normal
TS package, so keeping it together seems best. This seems like it'll
make setting up ESM builds easier.
glasser added a commit that referenced this pull request Jun 13, 2022
This reverts commit 0b58585.

This leaves the fix of adding cors and body-parser to server's deps and
leaves the removal of a TODO(AS4) about this.

The build process for this package is completely different from a normal
TS package, so keeping it together seems best. This seems like it'll
make setting up ESM builds easier.
glasser added a commit that referenced this pull request Jun 15, 2022
This reverts commit 0b58585.

This leaves the fix of adding cors and body-parser to server's deps and
leaves the removal of a TODO(AS4) about this.

The build process for this package is completely different from a normal
TS package, so keeping it together seems best. This seems like it'll
make setting up ESM builds easier.
glasser added a commit that referenced this pull request Jun 15, 2022
This reverts commit 0b58585.

This leaves the fix of adding cors and body-parser to server's deps and
leaves the removal of a TODO(AS4) about this.

The build process for this package is completely different from a normal
TS package, so keeping it together seems best. This seems like it'll
make setting up ESM builds easier.
glasser added a commit that referenced this pull request Jun 16, 2022
This reverts commit 0b58585.

This leaves the fix of adding cors and body-parser to server's deps and
leaves the removal of a TODO(AS4) about this.

The build process for this package is completely different from a normal
TS package, so keeping it together seems best. This seems like it'll
make setting up ESM builds easier.
glasser added a commit that referenced this pull request Jun 16, 2022
* Revert "Inline usage reporting protobuf into main package (#6515)"

This reverts commit 0b58585.

This leaves the fix of adding cors and body-parser to server's deps and
leaves the removal of a TODO(AS4) about this.

The build process for this package is completely different from a normal
TS package, so keeping it together seems best. This seems like it'll
make setting up ESM builds easier.

* plugins: Use dynamic import instead of manual intermediate functions

We want to avoid loading usage reporting protobuf until as late as
possible. Previously we had a specific file src/plugins/index.ts full of
little wrapper functions that call `require`. Now we use dynamic
`import` (which is compiled to CJS as `require` by tsc) instead.

We use "exports" in package.json to let you do deep imports from
particular files (only). Note that this still only supports CJS!

* Generate ESM and CJS files; change to deep-import API

The overall approach is to ask tsc to build two different projects for
package/server, one with CJS output and one with ESM, outputting into
two subdirectories of packages/server/dist. package.json teaches Node
how to find various entry points with both ESM and CJS.

To make the ESM version work, this equires making all "file imports"
(not `import type` or imports of packages) end with `.js`. Instead of
using `__dirname` we now update the version number in a normal TS file
before building.

We have to do some weird stuff with how we import the proto package
since it is not ESM-y enough due to the weird index.js in it. (Maybe we
should just fix our protobuf port to drop long support directly so we
can have a nicer index.js which is analyzed properly?)

We update the actual API so that `startStandaloneServer` must be
imported from `@apollo/server/standalone` (and thus express can be
tree-shaken if you don't use the standalone server) and so that the
various plugins are imported from `@apollo/server/plugin/usageReporting`
etc (and so you don't have to load protobuf stuff if you don't use it).

* scripts to subdir

* Make @apollo/usage-reporting-protobuf dual CJS/ESM too

This mostly involved running pbjs a second time to generate ESM. A few
tweaks were made to our fork `@apollo/protobufjs`:
- Long support is just turned off by default, so we don't need the
  wrapper index.* files that just turn it off
- The import line in generated code no longer includes `* as` since that
  didn't quite work in practice (it imported an object with a 'default'
  key on it)
- The `@apollo/protobufjs` package.json uses `exports` to show where
  `/minimal` is
@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.

None yet

2 participants