Can't query relationship in Block

default discord avatar
itsjxck
3 months ago
4

We're trying to use blocks to apply filter config to collection items.



I have a block defined like so:


const CategoryFilterBlock: Block = {
  slug: "CategoryFilter",
  fields: [
    {
      name: "categoryFilterType",
      label: "Type",
      type: "radio",
      options: ["whitelist", "blacklist"],
      defaultValue: "whitelist",
    },
    {
      name: "categories",
      type: "relationship",
      relationTo: Categories.slug,
      hasMany: true,
    },
  ],
};


Which is used on the collection like so:


{
  <collection_config>,
  {
    name: "filters",
    type: "blocks",
    blocks: [CategoryFilterBlock],
  }
}


I can query the

blockType

field and the

categoryFilterType

field, but I can't query for a value in the relationship:


// Works
{
  "filters.blockType": {
    equals: "CategoryFilter"
  }
}

// Also works
{
  "filters.categoryFilterType": {
    equals: "whitelist"
  }
}

// Doesnt work
{
  "filters.categories.label": {
    equals: "Some category label"
  }
}


Is this a bug or is this just outright not possible?

  • default discord avatar
    Mark | Omniux
    3 months ago

    Currently not possible I think. Extending the GraphQL capabilities of the API is a planned part of the roadmap

  • default discord avatar
    itsjxck
    3 months ago

    Should have mentioned this is with REST queries not GraphQL

  • discord user avatar
    jesschow
    Payload Team
    last month

    Hey @itsjxck are you still looking for help here?

  • default discord avatar
    itsjxck
    last month

    I don't know if this is still an issue or not as we parked the changes in favour of other work. I will retry and report back, but my assumption would be that it is probably fixed now

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.