Hi,
The relatedArticles field is returning an empty array or nulls, even though it is in the model.
below is my simple code i am trying to:
query {
contentFragmentByPath(_path: "/content/dam/articles/my-article") {
title
relatedArticles {
title
author
}
}
}
What might be the problem?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @OmarKh3,
The query looks fine to me, but if you're getting empty or null values for relatedArticles
, it's probably one of two things:
No content has been linked yet.
Even though the field exists in the model, if no related content fragments are actually selected in the authoring UI, the GraphQL query has nothing to return. It’s just empty by design.
The reference model isn’t exposed to GraphQL.
If relatedArticles
is a reference field pointing to another content fragment model, that model also needs to be enabled for GraphQL. Otherwise, AEM can’t resolve it properly in the schema or the response.
Can you try this?
Go into your content fragment in AEM and make sure you’ve actually picked one or more fragments in the relatedArticles
field.
Then, check if the target model (e.g., "Article") is published and has GraphQL enabled.
If you want to double-check what’s going on, run this simpler query first:
query {
contentFragmentByPath(_path: "/content/dam/articles/my-article") {
title
relatedArticles {
_path
}
}
}
Check if you’re getting _path
values back, it means the reference is resolving - so the problem is probably on the nested fields like title
or author
.
Hope that helps!
Hi @OmarKh3,
The query looks fine to me, but if you're getting empty or null values for relatedArticles
, it's probably one of two things:
No content has been linked yet.
Even though the field exists in the model, if no related content fragments are actually selected in the authoring UI, the GraphQL query has nothing to return. It’s just empty by design.
The reference model isn’t exposed to GraphQL.
If relatedArticles
is a reference field pointing to another content fragment model, that model also needs to be enabled for GraphQL. Otherwise, AEM can’t resolve it properly in the schema or the response.
Can you try this?
Go into your content fragment in AEM and make sure you’ve actually picked one or more fragments in the relatedArticles
field.
Then, check if the target model (e.g., "Article") is published and has GraphQL enabled.
If you want to double-check what’s going on, run this simpler query first:
query {
contentFragmentByPath(_path: "/content/dam/articles/my-article") {
title
relatedArticles {
_path
}
}
}
Check if you’re getting _path
values back, it means the reference is resolving - so the problem is probably on the nested fields like title
or author
.
Hope that helps!
@SantoshSai Thanks - the problem was that no related content had been linked in the dialog for the relatedArticles field.
Views
Replies
Total Likes
Hi @OmarKh3 ,
Try below steps:
1. Confirm Content Is Linked
Make sure your main content fragment (e.g., at /content/dam/articles/my-article) actually has references selected in the relatedArticles field.
- Go to AEM Assets.
- Open the Content Fragment for editing.
- Look at the relatedArticles field.
- Add one or more related content fragments if it's empty.
2. Verify Target Model Is Exposed to GraphQL
The content model used for relatedArticles must be enabled for GraphQL:
- Go to Tools → Assets → Content Fragment Models.
- Open your model (e.g., “Article”).
- Ensure "Enable GraphQL" is checked.
- Publish the model if not already published.
3. Confirm Field Is a Reference Field
Make sure the relatedArticles field is defined as a Content Reference (Single or Multi) in the content fragment model—not just text or JSON.
- It must point to another content fragment type (e.g., Article).
- It must not be a plain field with text or custom JSON.
4. Run Debug Query for _path
Run this trimmed-down query to confirm the references are at least resolving:
query {
contentFragmentByPath(_path: "/content/dam/articles/my-article") {
title
relatedArticles {
_path
}
}
}
If this returns _path values, that means:
- The references are present.
- The references are resolving properly.
- The issue is likely with nested fields (title, author), e.g., they may not exist on the referenced fragments.
5. Confirm Referenced Fragments Have the Fields You're Querying
Open each of the related content fragments and ensure:
- They are based on a model that includes title and author.
- These fields have values filled in.
- The model used for related fragments is published and GraphQL-enabled.
6. Use a Generic Fragment Query to Inspect Related Models
To explore what's available on a related fragment, run:
query {
contentFragmentByPath(_path: "/content/dam/articles/related-article-1") {
title
... on ArticleModel {
author
}
}
}
(Replace "ArticleModel" with the actual model name if different.)
Full Query Example
Once everything above is correct, this query will work:
query {
contentFragmentByPath(_path: "/content/dam/articles/my-article") {
title
relatedArticles {
_path
title
... on ArticleModel {
author
}
}
}
}
Note: You must use an inline fragment (... on ModelName) if you're accessing model-specific fields like author.
Regards,
Amit
Views
Likes
Replies
Views
Likes
Replies