diff --git a/package.json b/package.json index 400796b..27930a6 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/hydra/fetchResource.ts b/src/hydra/fetchResource.ts index b783da4..fcdf3ec 100644 --- a/src/hydra/fetchResource.ts +++ b/src/hydra/fetchResource.ts @@ -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"; @@ -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[], + }; + }); };