Skip to content

Commit b06eb64

Browse files
committed
docs: add reference example for getResourceCollectionFromContext
1 parent d666e5f commit b06eb64

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,37 @@ export class NextDrupalPages extends NextDrupal {
258258
/**
259259
* Gets a collection of resources from the context.
260260
*
261-
* @param {string} type The type of the resources.
262-
* @param {GetStaticPropsContext} context The static props context.
261+
* @param {string} type The type of the resources. Example: `node--article` or `user--user`.
262+
* @param {GetStaticPropsContext} context The static props context from getStaticProps or getServerSideProps.
263263
* @param {Object} options Options for the request.
264+
* - deserialize: Set to false to return the raw JSON:API response
264265
* @returns {Promise<T>} The fetched collection of resources.
266+
* @remarks
267+
* The localized resources will be fetched based on the `locale` and `defaultLocale` values from `context`.
268+
* @example
269+
* Get all articles from context
270+
* ```
271+
* export async function getStaticProps(context) {
272+
* const articles = await drupal.getResourceCollectionFromContext(
273+
* "node--article",
274+
* context
275+
* )
276+
*
277+
* return {
278+
* props: {
279+
* articles,
280+
* },
281+
* }
282+
* }
283+
* ```
284+
* Using TypeScript with DrupalNode for a node entity type
285+
* ```
286+
* import { DrupalNode } from "next-drupal"
287+
* const nodes = await drupal.getResourceCollectionFromContext<DrupalNode[]>(
288+
* "node--article",
289+
* context
290+
* )
291+
* ```
265292
*/
266293
async getResourceCollectionFromContext<T = JsonApiResource[]>(
267294
type: string,

0 commit comments

Comments
 (0)