Skip to content

Commit ed45ac9

Browse files
committed
fix(deps): don't depend on @apollo/client
1 parent 37cad36 commit ed45ac9

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

addon/apollo.js

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1-
import { setContext } from "@apollo/client/link/context";
2-
import { onError } from "@apollo/client/link/error";
1+
import { assert } from "@ember/debug";
2+
import {
3+
dependencySatisfies,
4+
macroCondition,
5+
importSync,
6+
} from "@embroider/macros";
37
import { handleUnauthorized } from "ember-simple-auth-oidc";
48

5-
export default function apolloMiddleware(httpLink, session) {
6-
const authMiddleware = setContext(async (_, context) => {
7-
await session.refreshAuthentication.perform();
9+
let apolloMiddleware;
810

9-
return {
10-
...context,
11-
headers: {
12-
...context.headers,
13-
...session.headers,
14-
},
15-
};
16-
});
11+
if (macroCondition(dependencySatisfies("@apollo/client", "^3.13.0"))) {
12+
const { setContext } = importSync("@apollo/client/link/context");
13+
const { onError } = importSync("@apollo/client/link/error");
1714

18-
const authAfterware = onError((error) => {
19-
if (error.networkError && error.networkError.statusCode === 401) {
20-
handleUnauthorized(session);
21-
}
22-
});
15+
apolloMiddleware = function apolloMiddleware(httpLink, session) {
16+
const authMiddleware = setContext(async (_, context) => {
17+
await session.refreshAuthentication.perform();
2318

24-
return authMiddleware.concat(authAfterware).concat(httpLink);
19+
return {
20+
...context,
21+
headers: {
22+
...context.headers,
23+
...session.headers,
24+
},
25+
};
26+
});
27+
28+
const authAfterware = onError((error) => {
29+
if (error.networkError && error.networkError.statusCode === 401) {
30+
handleUnauthorized(session);
31+
}
32+
});
33+
34+
return authMiddleware.concat(authAfterware).concat(httpLink);
35+
};
36+
} else {
37+
apolloMiddleware = () =>
38+
assert(
39+
"@apollo/client ^3.13.0 must be installed in order to use the apollo middleware",
40+
);
2541
}
42+
43+
export default apolloMiddleware;

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"prepare": "husky"
3232
},
3333
"dependencies": {
34-
"@apollo/client": "^3.13.0",
3534
"@babel/core": "^7.26.0",
3635
"@embroider/macros": "^1.16.11",
3736
"base64-js": "^1.5.1",
@@ -44,6 +43,7 @@
4443
"uuid": "^11.0.5 || ^12.0.0 || ^13.0.0"
4544
},
4645
"devDependencies": {
46+
"@apollo/client": "3.14.0",
4747
"@adfinis/eslint-config": "3.0.2",
4848
"@adfinis/semantic-release-config": "5.0.0",
4949
"@babel/eslint-parser": "7.28.4",
@@ -104,12 +104,18 @@
104104
"webpack": "5.102.1"
105105
},
106106
"peerDependencies": {
107+
"@apollo/client": "^3.13.0",
107108
"@ember-data/adapter": "~4.12.0 || >= 5.0.0 <= 5.3.11",
108109
"@embroider/macros": ">= 1.0.0",
109110
"ember-data": "~4.12.0 || >= 5.0.0 <= 5.3.11",
110111
"ember-simple-auth": ">= 6.0.0",
111112
"ember-source": ">= 4.12.0"
112113
},
114+
"peerDependenciesMeta": {
115+
"@apollo/client": {
116+
"optional": true
117+
}
118+
},
113119
"packageManager": "pnpm@10.18.3",
114120
"engines": {
115121
"node": ">= 20.11"

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)