Skip to content

Commit b214dd1

Browse files
authored
Merge pull request #8554 from apollographql/release-3.5
Release 3.5.0
2 parents d0e09f4 + e2d86b6 commit b214dd1

File tree

152 files changed

+19392
-30520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+19392
-30520
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ dist
3838
npm
3939
!flow-typed/npm
4040

41+
# Unpublished output from @apollo/client build, like bundlesize artifacts
42+
temp/
43+
4144
# webstorm
4245
.idea/
4346

CHANGELOG.md

+70
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1+
## Apollo Client 3.5.0 (2021-11-08)
2+
3+
### Improvements
4+
5+
- Add `updateQuery` and `updateFragment` methods to `ApolloCache`, simplifying common `readQuery`/`writeQuery` cache update patterns. <br/>
6+
[@wassim-k](https://github.com/wassim-k) in [#8382](https://github.com/apollographql/apollo-client/pull/8382)
7+
8+
- Field directives and their arguments can now be included along with field argument names when using [field policy `keyArgs: [...]` notation](https://www.apollographql.com/docs/react/pagination/key-args/). For example, if you have a `Query.feed` field that takes an argument called `type` and uses a `@connection(key:...)` directive to keep `feed` data from different queries separate within the cache, you might configure both using the following `InMemoryCache` field policy:
9+
```ts
10+
new InMemoryCache({
11+
typePolicies: {
12+
Query: {
13+
fields: {
14+
feed: {
15+
keyArgs: ["type", "@connection", ["key"]],
16+
},
17+
},
18+
},
19+
},
20+
})
21+
```
22+
[@benjamn](https://github.com/benjamn) in [#8678](https://github.com/apollographql/apollo-client/pull/8678)
23+
24+
- Report single `MissingFieldError` instead of a potentially very large `MissingFieldError[]` array for incomplete cache reads, improving performance and memory usage. <br/>
25+
[@benjamn](https://github.com/benjamn) in [#8734](https://github.com/apollographql/apollo-client/pull/8734)
26+
27+
- When writing results into `InMemoryCache`, each written object is now identified using `policies.identify` _after_ traversing the fields of the object (rather than before), simplifying identification and reducing duplicate work. If you have custom `keyFields` functions, they still receive the raw result object as their first parameter, but the `KeyFieldsContext` parameter now provides `context.storeObject` (the `StoreObject` just processed by `processSelectionSet`) and `context.readField` (a helper function for reading fields from `context.storeObject` and any `Reference`s it might contain, similar to `readField` for `read`, `merge`, and `cache.modify` functions). <br/>
28+
[@benjamn](https://github.com/benjamn) in [#8996](https://github.com/apollographql/apollo-client/pull/8996)
29+
30+
- Ensure `cache.identify` never throws when primary key fields are missing, and include the source object in the error message when `keyFields` processing fails. <br/>
31+
[@benjamn](https://github.com/benjamn) in [#8679](https://github.com/apollographql/apollo-client/pull/8679)
32+
33+
- The `HttpLink` constructor now accepts an optional `print` function that can be used to customize how GraphQL `DocumentNode` objects are transformed back into strings before they are sent over the network. <br/>
34+
[@sarahgp](https://github.com/sarahgp) in [#8699](https://github.com/apollographql/apollo-client/pull/8699)
35+
36+
- Make `@apollo/client/testing` a fully-fledged, independent entry point, instead of re-exporting `@apollo/client/utilities/testing` (which was never an entry point and no longer exists). <br/>
37+
[@benjamn](https://github.com/benjamn) in [#8769](https://github.com/apollographql/apollo-client/pull/8769)
38+
39+
- A new nested entry point called `@apollo/client/testing/core` has been created. Importing from this entry point instead of `@apollo/client/testing` excludes any React-related dependencies. <br/>
40+
[@wassim-k](https://github.com/wassim-k) in [#8687](https://github.com/apollographql/apollo-client/pull/8687)
41+
42+
- Make `cache.batch` return the result of calling the `options.update` function. <br/>
43+
[@benjamn](https://github.com/benjamn) in [#8696](https://github.com/apollographql/apollo-client/pull/8696)
44+
45+
- The `NetworkError` and `ErrorResponse` types have been changed to align more closely. <br/>
46+
[@korywka](https://github.com/korywka) in [#8424](https://github.com/apollographql/apollo-client/pull/8424)
47+
48+
- Include `graphql@16` in peer deps. <br/>
49+
[@brainkim](https://github.com/brainkim) in [#8997](https://github.com/apollographql/apollo-client/pull/8997)
50+
51+
### React Refactoring
52+
53+
#### Improvements (due to [@brainkim](https://github.com/brainkim) in [#8875](https://github.com/apollographql/apollo-client/pull/8875)):
54+
- The `useLazyQuery` function now returns a promise with the result.
55+
- The `useMutation` result now exposes a method which can be reset.
56+
57+
#### Bug Fixes (due to [@brainkim](https://github.com/brainkim) in [#8596](https://github.com/apollographql/apollo-client/pull/8596)):
58+
59+
- The `useQuery` and `useLazyQuery` hooks will now have `ObservableQuery` methods defined consistently.
60+
- Calling `useLazyQuery` methods like `startPolling` will start the query.
61+
- Calling the `useLazyQuery` execution function will now behave more like `refetch`. `previousData` will be preserved.
62+
- `standby` fetchPolicies will now act like `skip: true` more consistently.
63+
- Calling `refetch` on a skipped query will have no effect (issue [#8270](https://github.com/apollographql/apollo-client/issues/8270)).
64+
- Prevent `onError` and `onCompleted` functions from firing continuously, and improving their polling behavior.
65+
66+
### Other Bugs Fixed
67+
68+
- Update `zen-observable-ts` to eliminate transitive dependency on `@types/zen-observable`. <br/>
69+
[@benjamn](https://github.com/benjamn) in [#8695](https://github.com/apollographql/apollo-client/pull/8695)
70+
171
## Apollo Client 3.4.17 (2021-11-08)
272

373
### Improvements

config/entryPoints.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ const entryPoints = [
1717
{ dirs: ['react'] },
1818
{ dirs: ['react', 'components'] },
1919
{ dirs: ['react', 'context'] },
20-
{ dirs: ['react', 'data'] },
2120
{ dirs: ['react', 'hoc'] },
2221
{ dirs: ['react', 'hooks'] },
2322
{ dirs: ['react', 'parser'] },
2423
{ dirs: ['react', 'ssr'] },
24+
{ dirs: ['testing'], extensions: [".js", ".jsx"] },
25+
{ dirs: ['testing', 'core'] },
2526
{ dirs: ['utilities'] },
2627
{ dirs: ['utilities', 'globals'], sideEffects: true },
27-
{ dirs: ['testing'], extensions: [".js", ".jsx"] },
2828
];
2929

3030
const lookupTrie = Object.create(null);

config/helpers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function eachFile(dir: string, callback: (
2323

2424
// Avoid re-transforming CommonJS bundle files.
2525
if (relPath.endsWith(".cjs.js")) return;
26+
if (relPath.endsWith(".cjs")) return;
2627

2728
// Avoid re-transforming CommonJS bundle files.
2829
if (relPath.endsWith(".min.js")) return;

config/jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ module.exports = {
1717
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
1818
testURL: 'http://localhost',
1919
setupFiles: ['<rootDir>/config/jest/setup.ts'],
20+
testEnvironment: 'jsdom',
2021
};

config/prepareDist.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const distRoot = `${__dirname}/../dist`;
2323
const packageJson = require('../package.json');
2424
const entryPoints = require('./entryPoints.js');
2525

26+
// Enable default interpretation of .js files as ECMAScript modules. We don't
27+
// put this in the source ../package.json file because it interferes with tools
28+
// like ts-node, which we use to run various ../config/*.ts scripts.
29+
// TODO(benjamn) Fully diagnose that interference.
30+
packageJson.type = 'module';
31+
2632
// The root package.json is marked as private to prevent publishing
2733
// from happening in the root of the project. This sets the package back to
2834
// public so it can be published from the "dist" directory.
@@ -70,7 +76,8 @@ entryPoints.forEach(function buildPackageJson({
7076
path.join(distRoot, ...dirs, 'package.json'),
7177
JSON.stringify({
7278
name: path.posix.join('@apollo', 'client', ...dirs),
73-
main: `${bundleName}.cjs.js`,
79+
type: "module",
80+
main: `${bundleName}.cjs`,
7481
module: 'index.js',
7582
types: 'index.d.ts',
7683
sideEffects,

config/resolveModuleIds.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,45 @@ class Transformer {
8282
return id.startsWith("./") || id.startsWith("../");
8383
}
8484

85-
normalizeSourceString(file: string, source: Node | null | undefined) {
86-
if (source && n.StringLiteral.check(source) && this.isRelative(source.value)) {
85+
normalizeSourceString(file: string, source?: Node | null) {
86+
if (source && n.StringLiteral.check(source)) {
8787
try {
88-
source.value = this.normalizeId(source.value, file);
88+
source.value = this.isRelative(source.value)
89+
? this.normalizeId(source.value, file)
90+
: this.normalizeNonRelativeId(source.value, file);
8991
} catch (error) {
90-
console.error(`Failed to resolve ${source.value} in ${file}`);
92+
console.error(`Failed to resolve ${source.value} in ${file} with error ${error}`);
9193
process.exit(1);
9294
}
9395
}
9496
}
9597

98+
normalizeNonRelativeId(id: string, file: string) {
99+
const normal = this.normalizeId(id, file);
100+
const normalParts = normal.split("/");
101+
const sourceParts = id.split("/");
102+
const nodeModulesIndex = normalParts.lastIndexOf("node_modules");
103+
if (
104+
nodeModulesIndex >= 0 &&
105+
normalParts[nodeModulesIndex + 1] === sourceParts[0]
106+
) {
107+
const bareModuleIdentifier =
108+
normalParts.slice(nodeModulesIndex + 1).join("/");
109+
if (normal === this.normalizeId(bareModuleIdentifier, file)) {
110+
return bareModuleIdentifier;
111+
}
112+
console.error(`Leaving ${id} import in ${file} unchanged because ${
113+
bareModuleIdentifier
114+
} does not resolve to the same module`);
115+
}
116+
return id;
117+
}
118+
96119
normalizeId(id: string, file: string) {
97120
const basedir = path.dirname(file);
98121
const absPath = resolve.sync(id, {
99122
basedir,
123+
extensions: [".mjs", ".js"],
100124
packageFilter(pkg) {
101125
return pkg.module ? {
102126
...pkg,

config/rollup.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function prepareCJSMinified(input) {
7777
return {
7878
input,
7979
output: {
80-
file: input.replace('.js', '.min.js'),
80+
file: input.replace('.cjs', '.min.cjs'),
8181
format: 'cjs',
8282
},
8383
plugins: [
@@ -108,7 +108,7 @@ function prepareBundle({
108108
return isExternal(id, parentId, true);
109109
},
110110
output: {
111-
file: `${dir}/${bundleName}.cjs.js`,
111+
file: `${dir}/${bundleName}.cjs`,
112112
format: 'cjs',
113113
sourcemap: true,
114114
exports: 'named',
@@ -125,9 +125,9 @@ export default [
125125
// Convert the ESM entry point to a single CJS bundle.
126126
prepareCJS(
127127
'./dist/index.js',
128-
'./dist/apollo-client.cjs.js',
128+
'./dist/apollo-client.cjs',
129129
),
130130
prepareCJSMinified(
131-
'./dist/apollo-client.cjs.js',
131+
'./dist/apollo-client.cjs',
132132
),
133133
];

config/version.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ switch (process.argv[2]) {
3131
const {
3232
ApolloClient,
3333
InMemoryCache,
34-
} = require(path.join(distRoot, "core", "core.cjs.js"));
34+
} = require(path.join(distRoot, "core", "core.cjs"));
3535

3636
// Though this may seem like overkill, verifying that ApolloClient is
3737
// constructible in Node.js is actually pretty useful, too!
@@ -43,15 +43,15 @@ switch (process.argv[2]) {
4343
// the client might have acquired during its construction.
4444
client.stop();
4545

46-
// The CommonJS dist/core/core.cjs.js file is generated from ESM modules
47-
// generated by tsc, including dist/version.js, so verifying core.cjs.js
48-
// exports an ApolloClient class that defines client.version also serves
49-
// to verify that dist/version.js must have been correctly updated,
50-
// which is convenient because dist/version.js uses ECMAScript module
51-
// syntax, and is thus not importable in all versions of Node.js.
46+
// The CommonJS dist/core/core.cjs file is generated from ESM modules
47+
// generated by tsc, including dist/version.js, so verifying core.cjs
48+
// exports an ApolloClient class that defines client.version also serves to
49+
// verify that dist/version.js must have been correctly updated, which is
50+
// convenient because dist/version.js uses ECMAScript module syntax, and is
51+
// thus not importable in all versions of Node.js.
5252
assert.strictEqual(
5353
client.version, version,
54-
"Failed to update dist/version.js and dist/core/core.cjs.js",
54+
"Failed to update dist/version.js and dist/core/core.cjs",
5555
);
5656

5757
break;

0 commit comments

Comments
 (0)