Recently, I've encountered two issues while working with AEM GraphQL. I've looked through a lot of documentation but haven't found clear answers, so I’d like to ask here. Thank you in advance.
First issue:
Is it true that AEM GraphQL cannot query Content Fragments from two different models in a single request? Based on what I’ve found so far, it seems like this isn't supported.
Second issue:
AEM GraphQL seems to have syntax limitations when it comes to query logic. For example, I want to perform a search like:
publishTime AND (title OR overview)
But the actual behavior is:
publishTime AND title AND overview
Is there any known solution or workaround for this kind of query structure?
Any help would be greatly appreciated. Thank you!
Solved! Go to Solution.
Views
Replies
Total Likes
In the end, it wasn’t resolved — I still had to run multiple queries and then merge the results.
Views
Replies
Total Likes
Hi @ryuushihou1990,
You're correct - GraphQL does not support querying Content Fragments from different models in a single GraphQL query out of the box.
Each Content Fragment Model (CFM) is exposed via its own GraphQL schema endpoint. So when you fetch from:
/graphql/endpoint/modelA
...you’re only able to query CFs based on Model A. If you want to query from Model B, you must hit:
/graphql/endpoint/modelB
They’re isolated schemas, and GraphQL endpoint does not support schema stitching or federation.
Here is what you can do:If possible, refactor your fragments into a shared model with optional fields (not ideal for large scale). or Perform two separate queries and combine results in your app logic.
Now, to answer your 2nd question:
I think, this is another known limitation. GraphQL implementation (based on persisted queries and JCR indexing) doesn’t support nested logical groupings like publishTime AND (title OR overview).
Instead, it flattens all conditions with implicit AND.
Use _or and _and separately - but nesting within them is not truly supported the way native GraphQL allows.
Even if the schema lets you write _or, under the hood, AEM translates this to Lucene filters, which limits flexibility.
or
If logic is too complex, create a custom Sling Model servlet or GraphQL extension endpoint that implements the logic using JCR SQL2 or QueryBuilder.
Hi, @SantoshSai
Thank you very much for your detailed response.
Actually, I originally used AEM's QueryBuilder to perform the query. It supported nested conditions like:
publishTime AND (title OR overview),
which worked well at first. However, when the data volume increased (around 16,000 entries), the server began returning 500 errors.
As a result, I decided to switch to using AEM GraphQL.
Here’s the current approach I’m using:
Fetch publishTime from Model A.
Use _logop: or to fetch entries where title OR overview match.
Take the intersection of the two results to get ModelA_Result.
Fetch publishTime from Model B.
Use _logop: or to fetch entries where title OR overview match.
Again, take the intersection to get ModelB_Result.
Finally, merge ModelA_Result and ModelB_Result.
This approach has significantly improved the situation — at least the queries are now executing.
However, depending on the filter conditions, if the result set becomes too large, I still sometimes get 500 errors.
If possible, could you suggest a more stable or scalable solution?
I would greatly appreciate any advice.
Views
Replies
Total Likes
@ryuushihou1990 In one single persistent query you can get the data from two models which is possible.
I have Model1 and Model2 and when creating model2 I will put reference of model1 like using fragment reference and this is called nested fragment implementation. And in the query I can get data from model1 and model2 as well.
You can go though below documentation and see nested queries.
Also check for the all available filters for AND or OR conditions.
@Uppari_Ramesh
First of all, thank you for your response.
If you’re able to query both models at the same time, could you please share an example with me?
Views
Replies
Total Likes
Hi @ryuushihou1990 ,
I will share the adobe examples, please go through below screenshots and search for the same text in screenshot in the URL.
Below screen shot is pre-requisite for achieving calling 2 models in a single query:
Below SS is example of how you can refer 2 models in a single query.
Please go though fragment reference concept once, you will get the full idea.
Thanks,
Ramesh.
@Uppari_Ramesh
Thank you very much for sharing!! I’ll give it a try.
@ryuushihou1990 Did you find the suggestions helpful? If you need more information, please let us know. If a response resolved your issue, kindly mark it as correct to help others in the future. Alternatively, if you discovered a solution on your own, we'd appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
In the end, it wasn’t resolved — I still had to run multiple queries and then merge the results.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies