Skip to content

Commit 61488cd

Browse files
committed
docs: add additional detail to getResource entry
1 parent 16c6e0b commit 61488cd

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

packages/next-drupal/src/next-drupal.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ export class NextDrupal extends NextDrupalBase {
290290
/**
291291
* Fetches a resource of the specified type by its UUID.
292292
*
293-
* @param {string} type The type of the resource.
294-
* @param {string} uuid The UUID of the resource.
293+
* @param {string} type The resource type. Example: `node--article`, `taxonomy_term--tags`, or `block_content--basic`.
294+
* @param {string} uuid The id of the resource. Example: `15486935-24bf-4be7-b858-a5b2de78d09d`.
295295
* @param {JsonApiOptions & JsonApiWithCacheOptions & JsonApiWithNextFetchOptions} options Options for the request.
296296
* @returns {Promise<T>} The fetched resource.
297297
* @examples
@@ -332,6 +332,27 @@ export class NextDrupal extends NextDrupalBase {
332332
* cacheKey: `node--article:${id}`,
333333
* })
334334
* ```
335+
* Get a page resource with time-based revalidation.
336+
* ```ts
337+
* const node = await drupal.getResource(
338+
* "node--page",
339+
* "07464e9f-9221-4a4f-b7f2-01389408e6c8",
340+
* { next: { revalidate: 3600 } }
341+
* )
342+
* ```
343+
* Get a page resource with tag-based revalidation.
344+
* ```ts
345+
* const {slug} = params;
346+
* const path = drupal.translatePath(slug)
347+
*
348+
* const type = path.jsonapi.resourceName
349+
* const tag = `${path.entity.type}:${path.entity.id}`
350+
*
351+
* const node = await drupal.getResource(path, path.entity.uuid, {
352+
* params: params.getQueryObject(),
353+
* tags: [tag]
354+
* })
355+
* ```
335356
* Using DrupalNode for a node entity type.
336357
* ```ts
337358
* import { DrupalNode } from "next-drupal"

packages/next-drupal/src/types/options.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ export interface FetchOptions extends RequestInit {
1010
withAuth?: boolean | NextDrupalAuth
1111
}
1212

13+
/**
14+
* JSON:API Related Options
15+
*/
1316
export type JsonApiOptions = {
17+
/**
18+
* Set to false to return the raw JSON:API response.
19+
* */
1420
deserialize?: boolean
21+
/**
22+
* JSON:API params such as `filter`, `fields`, `include` or `sort`.
23+
*/
1524
params?: JsonApiParams
1625
} & JsonApiWithAuthOption &
1726
(
1827
| {
28+
/** The locale to fetch the resource in. */
1929
locale: Locale
30+
/** The default locale of the site. */
2031
defaultLocale: Locale
2132
}
2233
| {
@@ -26,11 +37,14 @@ export type JsonApiOptions = {
2637
)
2738

2839
export type JsonApiWithAuthOption = {
40+
/** Set to true to use the authentication method configured on the client. */
2941
withAuth?: boolean | NextDrupalAuth
3042
}
3143

3244
export type JsonApiWithCacheOptions = {
45+
/** Set `withCache` if you want to store and retrieve the resource from cache. */
3346
withCache?: boolean
47+
/** The cache key to use. */
3448
cacheKey?: string
3549
}
3650

@@ -39,5 +53,8 @@ export type JsonApiWithNextFetchOptions = {
3953
cache?: RequestCache
4054
}
4155
// TODO: Properly type this.
56+
/**
57+
* JSON:API params such as filter, fields, include or sort.
58+
*/
4259
/* eslint-disable @typescript-eslint/no-explicit-any */
4360
export type JsonApiParams = Record<string, any>

www/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"dev": "typedoc --tsconfig tsconfig.docs.json && next dev -p 4444",
1010
"build": "typedoc --tsconfig tsconfig.docs.json && next build",
1111
"preview": "typedoc --tsconfig tsconfig.docs.json && next build && next start -p 4444",
12-
"generate:api-docs": "typedoc --tsconfig tsconfig.docs.json"
12+
"generate:api-docs": "typedoc --tsconfig tsconfig.docs.json",
13+
"watch:api-docs": "typedoc --tsconfig tsconfig.docs.json --watch"
1314
},
1415
"dependencies": {
1516
"@docsearch/react": "^3.6.0",

0 commit comments

Comments
 (0)