Commit b1bd747
authored
Move utility functions out of
* Move utility functions out of `apollo-env`, leaving polyfills.
The `apollo-env` package has a number of purposes today, including providing
polyfills for runtimes that lack more modern features, providing utility
functions (like, `createHash` that works on non-Node.js environments) and
offering some common predicate functions like `isNotNullOrUndefined` - a
method that we use in many places in the Apollo ecosystem.
The polyfills have proven useful on environments that necessitate them,
offering newer ECMAScript functionality in runtimes that don't yet have
them, but they're automatically loaded from the main module entry point of
this library, rather than being selectively enabled. For example, it's not
uncommon to see `import 'apollo-env';` in other packages that rely on the
functionality.
It's this automatic eager loading of polyfills that proves to be problematic
when the _utilities_ and _predicate_ functions of this library come into
play though. Imagine a package that merely needs to use a version of
`createHash` that simply falls back gracefully to a JavaScript version, or a
function that wants to utilize the useful `mapValues` function, but in a
circumstance where we - or our users - don't want to be subjected to the
nature of polyfills affecting the runtime (see related issues like
apollographql/apollo-server#2634).
Another circumstance that arises, which was the most motivating factor in
this case, is that the `apollo-env` package has consistently proven
difficult for bundlers to traverse, possibly because of the polyfills,
possibly because of the side-effects, possibly because of both! However,
in my times trying to bundle our Apollo packages over the years, I've
encountered problems with Webpack, Snowpack, Rollup.js and now esbuild.
Most of these functions are small enough and simple enough that the
duplication cost isn't all that high. For example, in my changes in this
commit, rather than paying the cost of relying on an other package for what
is basically a one-line function, I've just copied and pasted
`isNotNullOrUndefined` into a couple places where it is needed.
Furthermore, since most of the utilities that were being leveraged from
`apollo-env` were being leveraged _by_ the `apollo-graphql` package, I've
just moved those into that package instead.
Any runtimes that still necessitate polyfills like `Array.prototype.flat` or
`Array.prototype.flatMap` can still `import "apollo-env";` directly for
those side-effects to be applied to their runtme, and packages that just
need the utilities can rely on `apollo-graphql`. Again though, most of
our packages are depending on both already so creating the more distinct
separation seems not-all-that-unreasonable. Furthermore, while `apollo-env`
does also provide some `fetch` polyfills, once Node.js 12 becomes the minimum
version we support, I don't think we even need those polyfills anymore at all.
* Cease using ES features which don't exist natively on our target platforms
Honestly, this whole attempt to use modern ECMAScript features before they
were ready and truly supported in the runtimes we support was I think a
great experiment, but not worth the struggle. We still support Node.js 10
for a couple more weeks, but this is a constraint for me today and it's
(being, generally the `apollo-server-env` and the `apollo-env` package's
polyfills) have been a constraint _many_ times over.
Put another way, I don't think the Pandora's box of "polyfills" is worth
it for things like `Array.protytype.flat`, which are not so inherently
complex that they can't be abstracted into a small function.
The `core-js-pure` package does a pretty good job offering this
functionality without necessitating us in-house/vendor it ourselves, but it
- sadly - does not provide TypeScript types, unlike the `core-js` core
itself.
* Update packages/apollo-graphql/src/schema/buildSchemaFromSDL.tsapollo-env, leaving polyfills. (#2274)1 parent 61974b9 commit b1bd747
15 files changed
Lines changed: 52 additions & 25 deletions
File tree
- packages
- apollo-env/src
- utils
- apollo-graphql
- src
- schema
- types
- utilities
- apollo/src/commands/service
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | 58 | | |
| 59 | + | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
| |||
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
33 | | - | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
159 | | - | |
| 165 | + | |
160 | 166 | | |
161 | 167 | | |
162 | 168 | | |
| |||
170 | 176 | | |
171 | 177 | | |
172 | 178 | | |
173 | | - | |
| 179 | + | |
174 | 180 | | |
175 | 181 | | |
176 | 182 | | |
| |||
182 | 188 | | |
183 | 189 | | |
184 | 190 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
189 | 196 | | |
190 | 197 | | |
191 | 198 | | |
| |||
295 | 302 | | |
296 | 303 | | |
297 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments