JSON:API Params
How to use Drupal JSON-API Params to query and filter resources.
next-drupal has support for Drupal JSON:API Params, a helper for building query params.
You use query params for filtering, sorting and paginating resources returned by JSON:API.
Installation
yarn add drupal-jsonapi-params
Usage
import { DrupalNode } from "next-drupal"import { DrupalJsonApiParams } from "drupal-jsonapi-params"
export default async function ArticlePage() { const params = new DrupalJsonApiParams() .addFields("node--article", ["title", "path", "body", "uid"]) .addFilter("status", "1") .addInclude(["uid.user_picture"]) .addSort("created", "DESC")
const article = await drupal.getResourceCollection<DrupalNode[]>( "node--article", { params: params.getQueryObject(), } )}
You can read more about Drupal JSON:API Params here.