Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to correctly access nested fields #277

Closed
MartinConde opened this issue Oct 2, 2024 · 3 comments
Closed

how to correctly access nested fields #277

MartinConde opened this issue Oct 2, 2024 · 3 comments
Labels
question Further information is requested workaround available

Comments

@MartinConde
Copy link

I feel like I'm missing something obvious but after not being able to figure it for a while, I figured I'd ask here.
I have some nested blocks, which when using the "regular" sdk, I can get like so:

...
fields: [
  "*",
  {
    blocks: [
      "collection",
      {
        item: {
          block_hero: ["*"],
          block_intro: ["*"],
          block_cards: ["*"],
          block_image: ["*"],
          block_gallery: ["*.*"],
        },
      },
    ],
  },
];

However when I try to do the same thing using this module and following the useAsyncData example in the docs, it doesn't return any of the blocks, only the first set of "first-level" fields that it grabs using '*'.`
Doing something like

fields: ['*.*.*.*']

does return everything but I'd just like to figure out how to properly return the selected data.

Any pointers on what I might be missing to get this working would be much appreciated!

@MartinConde MartinConde added the question Further information is requested label Oct 2, 2024
@sandros94
Copy link
Collaborator

That is indeed an SDK only feature, for now.

Since version 5.x of this module (and the current rewrite, still unreleased, at #273 ) are based on Nuxt's $fetch we must work with the normal RestAPI syntax, this means that in your usecase you would have something like:

fields: [
  '*',
  'blocks.collection',
  'blocks.item.block_hero.*',
  'blocks.item.block_intro.*',
  'blocks.item.block_cards.*',
  'blocks.item.block_image.*',
  'blocks.item.block_gallery.*.*',
]

Please remember that you can have * wildcard in-between levels, like: *.item.* or blocks.*.*.id

This might be something I will experiment with in a later date.

@MartinConde
Copy link
Author

Thanks a lot! Just in case anybody else stumbles upon this, the simplest way to get a list of all the blocks with the respective collection name for conditional rendering and whatnot, was simply:

fields: [
      'blocks.collection',
      'blocks.item.*',
]

@sandros94 sandros94 changed the title How to correctly access nested Blocks how to correctly access nested fields Oct 2, 2024
@sandros94
Copy link
Collaborator

I'm going to close this for now, since I would like to focus on an initial release of the rewrite and revisit this in a later date.

Please do comment or re-open it if something might come to mind!

@sandros94 sandros94 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested workaround available
Projects
None yet
Development

No branches or pull requests

2 participants