Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Graphql Fragment not resolving fields

Avatar

Level 2

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?

3 Replies

Avatar

Community Advisor

Hi @Flowlicious 

Try with the below query ( defining fragment for TestModelResults)

 

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

 

 

Avatar

Level 2

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

Avatar

Level 2

sorry, although your query works, this is not the "solution".. this is a workaround and simply a different query.. the question is why only standard properties are visible when trying it in the fragment and why the others are not fetching data.