[SOLVED] Search or filter Assets using GraphQL API


#1

I’m using the following GraphQL query to get a list of Assets.

{
    queryAssets {
        fileName
        slug
        url
    }
}

However, I don’t want all Assests, just specific ones. I am currently having two issues.

First, even though the Squidex UI exposes a Tags field, the GraphQL API does not (AssetDto).
06%20PM

Second, the GraphQL API for queryAssets shows a search parameter of type String. Assuming that it works the same as the OData $search, I tried the following but received the error “Error trying to resolve queryAssets.”

{
    queryAssets(search: "dashboard") {
        fileName
        slug
        url
    }
}

In fact, I receive this error with any string I use for search, except for the empty string.

I’ve seen this and tried appending it to the GraphQL endpoint but it does not seem to have any effect.
$filter=startswith(slug, ‘dashboard’)

A couple of questions,

  1. Is it possible to search for Assets based on a tag value?
  2. Using GraphQL, how can I search (or filter) Assets based on a slug (or tag)?

#2

The search Parameter is an OData filter.


#3

Thanks, but would you mind sharing the format of the search parameter? I tried using the following OData filter variations without success:

queryAssets(search: "$filter = startswith(slug,'dashboard')") { ... }
queryAssets(search: "filter = startswith(slug,'dashboard')") { ... }
queryAssets(search: "startswith(slug,'dashboard')") { ... }

I have also tried the three variations above using “slug eq ‘dashboard-map-teachers.pdf’”. I always get the error “Error trying to resolve queryAssets.”


#4

Hi,

it was actually a bug. I pushed the fix to the master branch.

If you use Cloud: I will deploy it on Monday.


#5

Thanks for the bug fix.

Could you please explain the search parameter format and how to use it? I still cannot get it to work using my examples above.


#6

I just deployed it, was not able to do it before. The search parameter is gone and the new filter is an Odata filter.


#7

Sebastian,

Thanks for your help. I apologize for keeping this post alive but the filter seems to only work for some fields and not all fields in AssetsDto!

For example, this works queryAssets(filter:"contains(fileName, 'dashboard')") but this returns the usual error message queryAssets(filter:"contains(slug, 'dashboard')"). As you can see, I only changed the field name and I have “dashboard” in both fileName and slug.

In fact, slug is not the only String! field for which the filter produces error messages. Do you have any documentation or reference regarding which fields can be filtered?


#8

You are right. I have to manually register fields to the query system and have forgotten to do it for slug and fileHash.

It is fixed and build is running.


#9

I have deployed the update with all fields.


#10

:clap:t4: Thank you!


#11

Does it work now as expected?