Skip to main content
Level 2
April 19, 2022

Graphql Fragment not resolving fields

  • April 19, 2022
  • 1 reply
  • 1542 views

i am using Adobe AEM with GraphQL and i am trying to use Fragments here (because i want to query the data with Gatsby.js, but this is not related i think).

When i try to run this Query:

 

{ testList { items { typename headline } } }

 

the result is

 

{ "data": { "testList": { "items": [ { "__typename": "TestModel", "headline": "test headline" }, { "__typename": "TestModel", "headline": "Test headline two" } ] } } }

 

which looks fine.. BUT when i try to query with fragments, the field is getting no data (headline is null)

{ testList { items { __typename ...TestModelFragment } } } fragment TestModelFragment on TestModel { headline } { "data": { "testList": { "items": [ { "__typename": "TestModel", "headline": null }, { "__typename": "TestModel", "headline": null } ] } } }

can someone explain this or am i missing something here?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Vijayalakshmi_S
Level 10
April 19, 2022

Hi @floriangr 

Try with the below query ( defining fragment for TestModelResults)

 

{
    testList{
        ...TestModelFragment
    }
}
fragment TestModelFragment on TestModelResults{
    items{
        headline
    }
}

 

 

FlorianGrAuthor
Level 2
April 19, 2022

This works.. but why? Is there a way to make it work like i did?