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

fix(hydra): hydra prefix optional (remove hardcoded values) #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"dependencies": {
"graphql": "^16.0.0",
"inflection": "^1.13.0",
"jsonld": "^8.1.0",
"jsonld": "^8.3.2",
"jsonref": "^8.0.0",
"lodash.get": "^4.4.0",
"tslib": "^2.0.0"
Expand Down
19 changes: 13 additions & 6 deletions src/hydra/fetchResource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import get from "lodash.get";
import type { EmptyResponseDocument, ResponseDocument } from "./fetchJsonLd.js";
import fetchJsonLd from "./fetchJsonLd.js";
import type { IriTemplateMapping, RequestInitExtended } from "./types.js";

Expand All @@ -9,10 +10,16 @@ export default (
return fetchJsonLd(
resourceUrl,
Object.assign({ itemsPerPage: 0 }, options)
).then((d) => ({
parameters: get(
d,
"body.hydra:search.hydra:mapping"
) as unknown as IriTemplateMapping[],
}));
).then((d: ResponseDocument | EmptyResponseDocument) => {
let hasPrefix = true;
if ((d as ResponseDocument).body) {
hasPrefix = "hydra:search" in (d as ResponseDocument).body;
}
return {
parameters: get(
d,
hasPrefix ? "body.hydra:search.hydra:mapping" : "body.search.mapping"
) as unknown as IriTemplateMapping[],
};
});
};
Loading