GraphQL query and filter

Hi Sebastian,

I have a few questions about Squidex filter on GraphQL request.

  1. From the doc in /api/graphql, It seem like Squidex is using OData filter on top of GraphQL. Is Squidex also support normal GraphQL query ? If it supported, Could I ask for the example queries please ? I tried by myself and it’s not working.

  2. Does Squidex GraphQL support $expand param ? I want to filter the content from the ref object. eg. get users from company “ABC”.

  3. How to exclude the content with empty ref object ? eg. get users with any companies except users without selected company. I tried some methods like “ne null” and “/$count gt 0” but it didn’t work.

  4. How to filter the text with wildcard ? eg. input “Alb” and then it returns users with “Alb” in their name.

Thank you

Hi

  1. GraphQL uses OData as filter system. The reason is that I did not want to write a custom (or second) query system. You can find examples here: https://docs.squidex.io/guides/02-api#usdfilter. What is a normal GraphQL query?

  2. No, it does not make sense with GraphQL I think. Do you have a reference from users to company? If yes you have to take the company id and use a simple eq filter `$filter=company eq ‘123…’``

  3. Good question. Have to try it myself.

  4. See the link in first answer. contains is your friend.

I am working on a custom empty function. Should be ready soon.

I have pushed the empty function. It works for string, assets and references.

The syntax is $filter=empty(data/firstName/iv)

Thank you very much. I’m very appreciated for your help.

The empty filter works great. Btw I still cannot use simple eq filter on ref object.

eg.
queryUsersContents
(filter: " data/company/iv/data/name/iv eq ‘123’ ")

I got the error “Error trying to resolve queryUsersContents.”. I also went to the logfile for more information about the error but didn’t find anything logged.

You cannot traverse the references when you write your odata queries.

Hi Sebastian,

Just a follow-up on the first item on the OP’s question- In other headless CMSes (I’ve looked at GraphCMS and Strapi) the queries would look something like

query {
  contents(where: { fieldA: "value1" AND: { fieldB_gt: 10  }, orderBy: createdAt_ASC) {
    fieldA,
    fieldB,
    fieldC
  }
}

Are there plans to implement this style of queries?

It would also be great if “iv” does not need to be specified on each field in the filter string. In cases where there are multiple languages, a single “iv” would probably suffice? I assume consumers would normally need the values in only 1 language when querying. What I mean is something like

query {
  contents(partition: "en", where: { fieldA: "value1" AND: { fieldB_gt: 10  }, orderBy: createdAt_ASC) {
    fieldA,
    fieldB,
    fieldC
  }
}

Hi Leo,

I have already thought about this problem and implemented an abstraction over the query system so that I can also implement other syntaxes. With the current implementation it is difficult to have a shortcut for iv, you have either to flatten all fields and specify a language or write another query language.

Awesome, thanks for the response!

I also need to do exact same thing as Kasidit_Khamfoo filter query in graphql.
Is there any alternative way to filter the reference data fields?
eg:
{ queryArticlesContents(filter: “data/categories/iv/data/slug/iv eq ‘entertainment’”) { data { …} } }

1 Like

It sound like you want to filter the referenced contents, right? This sounds like a different requirement to me.

You can filter using below approach:

querySchemaXContents(filter: “data/SchemaY-RefField/iv eq ‘schemaY-Id’”) { … }

Instead of a single call you can cascade 2 requests/calls to go deeper

1 Like