Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6eb3867

Browse files
fix(hydra): hydra prefix optional (remove hardcoded values) (#139)
Co-authored-by: Valentin Dassonville <valentin.dassonville@les-tilleuls.coop>
1 parent e8b49f2 commit 6eb3867

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"dependencies": {
4141
"graphql": "^16.0.0",
4242
"inflection": "^1.13.0",
43-
"jsonld": "^8.1.0",
43+
"jsonld": "^8.3.2",
4444
"jsonref": "^8.0.0",
4545
"lodash.get": "^4.4.0",
4646
"tslib": "^2.0.0"

‎src/hydra/fetchResource.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import get from "lodash.get";
2+
import type { EmptyResponseDocument, ResponseDocument } from "./fetchJsonLd.js";
23
import fetchJsonLd from "./fetchJsonLd.js";
34
import type { IriTemplateMapping, RequestInitExtended } from "./types.js";
45

@@ -9,10 +10,16 @@ export default (
910
return fetchJsonLd(
1011
resourceUrl,
1112
Object.assign({ itemsPerPage: 0 }, options)
12-
).then((d) => ({
13-
parameters: get(
14-
d,
15-
"body.hydra:search.hydra:mapping"
16-
) as unknown as IriTemplateMapping[],
17-
}));
13+
).then((d: ResponseDocument | EmptyResponseDocument) => {
14+
let hasPrefix = true;
15+
if ((d as ResponseDocument).body) {
16+
hasPrefix = "hydra:search" in (d as ResponseDocument).body;
17+
}
18+
return {
19+
parameters: get(
20+
d,
21+
hasPrefix ? "body.hydra:search.hydra:mapping" : "body.search.mapping"
22+
) as unknown as IriTemplateMapping[],
23+
};
24+
});
1825
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /