Skip to content

Commit d666e5f

Browse files
committed
docs: add reference examples to getResourceCollection
1 parent 32d40b1 commit d666e5f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ yarn-error.log*
4242
/drupal/web/phpunit.xml
4343
/drupal/web/sites/default/settings.local.php
4444
/drupal-*
45+
/local-next-drupal

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,34 @@ export class NextDrupal extends NextDrupalBase {
571571
/**
572572
* Fetches a collection of resources of the specified type.
573573
*
574-
* @param {string} type The type of the resources.
574+
* @param {string} type The type of the resources. Example: `node--article` or `user--user`.
575575
* @param {JsonApiOptions & JsonApiWithNextFetchOptions} options Options for the request.
576+
* - deserialize: Set to false to return the raw JSON:API response
576577
* @returns {Promise<T>} The fetched collection of resources.
578+
* @example
579+
* Get all articles
580+
* ```
581+
* const articles = await drupal.getResourceCollection("node--article")
582+
* ```
583+
* Using filters
584+
* ```
585+
* const publishedArticles = await drupal.getResourceCollection("node--article", {
586+
* params: {
587+
* "filter[status]": "1",
588+
* },
589+
* })
590+
* ```
591+
* Get the raw JSON:API response
592+
* ```
593+
* const { data, meta, links } = await drupal.getResourceCollection("node--page", {
594+
* deserialize: false,
595+
* })
596+
* ```
597+
* Using TypeScript with DrupalNode for a node entity type
598+
* ```
599+
* import { DrupalNode } from "next-drupal"
600+
* const nodes = await drupal.getResourceCollection<DrupalNode[]>("node--article")
601+
* ```
577602
*/
578603
async getResourceCollection<T = JsonApiResource[]>(
579604
type: string,

0 commit comments

Comments
 (0)