getResourceCollectionFromContext
Fetch a collection of resources from getStaticProps or getServerSideProps context.
const resource = await drupal.getResourceCollectionFromContext<T = JsonApiResource[]>( type, context, options?: { params, withAuth, deserialize, locale, defaultLocale, }): Promise<T>type: string- Required
- The resource type. Example:
node--articleoruser--user.
context: GetStaticPropsContext | GetServerSidePropsContext- Required
- The context from
getStaticPropsorgetServerSideProps.
options- Optional
params: JsonApiParams: JSON:API params such asfilter,fields,includeorsort.withAuth: boolean | DrupalClientAuth:- Set the authentication method to use. See the authentication docs.
- Set to
trueto use the authentication method configured on the client.
deserialize: boolean: Set to false to return the raw JSON:API response.locale: string: The locale to fetch the resource in.defaultLocale: string: The default locale of the site.
Notes
- The localized resources will be fetched based on the
localeanddefaultLocalevalues fromcontext.
Examples
- Get all articles from context.
pages/[[...slug]].tsx
export async function getStaticProps(context) { const articles = await drupal.getResourceCollectionFromContext("node--article", context)
return { props: { articles, }, }}TypeScript
- Using
DrupalNodefor a node entity type.
import { DrupalNode } from "next-drupal"
const nodes = await drupal.getResourceCollectionFromContext<DrupalNode[]>( "node--article", context)See the TypeScript docs for more built-in types.
