question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about getResourceFromContext and getResourceCollectionFromContext

See original GitHub issue

Hi,

I try to use getResourceFromContext and getResourceCollectionFromContext, are there supposed to do the same thing ?

For example, i want to retrieve a specific node by nid. With getResourceCollectionFromContext, this is fine, i get an array with the node in it.

const node = await drupal.getResourceCollectionFromContext<DrupalNode[]>("node--page", context, {
  params: getParams("node--page").addFilter("nid", "2").getQueryObject(),
})

but if i do the same thing with getResourceFromContext, i got null response

const node = await drupal.getResourceFromContext<DrupalNode>("node--page", context, {
  params: getParams("node--page").addFilter("nid", "2").getQueryObject(),
})

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
shadcncommented, Oct 15, 2022

Yeah a getResourceCollection with a filter should do the trick.

const pages = await drupal.getResourceCollection("node--page", {
  params: {
    "filter[drupal_internal__nid]": 1,
  },
})

const [page] = pages
0reactions
spiderneocommented, Oct 15, 2022

Yes I saw that but sometimes I need to use a nid 😃 i’ll do with collection it works fine 😉

I just can’t manage to get the node by slug / alias with getResourceFromContext which is weird 😃

Thank you anyway for your answers and Work on this ! For now i manage to do what i want with this module !

Read more comments on GitHub >

github_iconTop Results From Across the Web

getResourceCollectionFromCont...
getResourceCollectionFromContext. Fetch a collection of resources from getStaticProps or getServerSideProps context.
Read more >
Decoupled Drupal with Next.JS using Next-Drupal - Axelerant
The primary methods that we used to get data in our application are getResourceCollectionFromContext and getResourceFromContext.
Read more >
How to progressively decouple your Drupal site with Next.js ...
getResourceCollectionFromContext is a helper function from next-drupal. ... getResourceFromContext(path, context, { params: new ...
Read more >
Next.js on Acquia: Customizing content types
import { getResourceCollectionFromContext } from "next-drupal" import ... node = await getResourceFromContext<DrupalNode>(type, context, ...
Read more >
next-drupal - bytemeta
Question about getResourceFromContext and getResourceCollectionFromContext. Transformative-JY. Transformative-JY OPEN.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found