Optimizely Graph .NET -- Try to add fragment

Vote:
 

I am trying to create a query with fragment and hopefully to get the query like this. 

query ArticleListing {
  ArticlePage {
    items {
      Name
      Url
      Title
      PreviewImage {
        Expanded {
          ...Image
        }
      }
    }
    total
  }
}
fragment Image on ImageFile {
  Name
  Url
  Title
  Width
  Height
}

I have a code below so far

            var fragmentImage = new FragmentBuilder<ImageFile>("Image").Fields(x => x.Name
                                                                                , x => x.Url
                                                                                , x => x.Title
                                                                                , x => x.Width
                                                                                , x => x.Height);

            articleQuery = articleQuery
                                .Fields(x => x.Name, x => x.Url, x => x.Title)
                                .Field(x => x.PreviewImage.Expanded).AddFragments(fragmentImage);

But it puts the "...Image" outside the PreviewImage.Expanded

query ArticleListing {
  ArticlePage {
    items {
      Name
      Url
      Title
      PreviewImage {
        Expanded
      }
      ...Image
    }
    total
  }
}

fragment Image on ImageFile {
  Name
  Url
  Title
  Width
  Height
}

Is there a way to make fragment to be in the PreviewImage.Expanded ?

#331105
Oct 08, 2024 13:00
Vote:
 

Hi,

What is Optimizely CMS version and Graph Client .NET version that you are using?

#331163
Oct 09, 2024 8:25
Vote:
 

hi Binh Nguyen Thi,

The Optimizely CMS is 12.29.1, and the Optimizely.Graph.Client version is 1.2.0

#331164
Oct 09, 2024 8:51
Vote:
 

Hi Nattawut,

Optimizely.Graph.Client version is 1.2.0 doesn't support fragment in a specific field unfortunately. This should be a missing part and need to be updated. In the meanwhile please select fields directly in the query builder or build a small part of ArticlePage for reuseable.

  var fragmentForImage = new FragmentBuilder<ArticlePage>("PreviewImageFragment")
         .Fields(_=> _.PreviewImage.Expanded.Name, _ => _.PreviewImage.Expanded.Url, _ => _.PreviewImage.Expanded.Height);

   articleQuery = articleQuery
         .Fields(x => x.Name, x => x.Url, x => x.Title)
          .AddFragments(fragmentForImage);
#332489
Nov 06, 2024 4:25
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.