2

Is there an easy way to return all fields, while skipping standard Sitecore fields in GraphQL query results without strongly-typed items? I know that I can use fields(ownFields:true), but it will remove inherited fields from all templates, but I want to skip only standard ones with __ prefix.

I have exclusions of standard field in my configuration, but this removes standard fields only from the schema, but not from query results:

<fieldFilter type="Sitecore.Services.GraphQL.Content.TemplateGeneration.Filters.StandardFieldFilter, Sitecore.Services.GraphQL.Content">
      <exclusions hint="raw:AddFilter">
           <exclude name="__*" />
      </exclusions>
</fieldFilter>
2
  • It might help if you can also share your sample GraphQL query to add more context and help with potential answers to your question. – Julius A Mar 23 at 17:52
  • I don't have specific query, I'm looking for generic approach to solve this issue, without the need of listing every field in my query via strongly-typed fragment. – whuu Mar 23 at 20:04
1

Without a sample query reference to tailor my answer, I think what you could leverage here are query fragments to help with multiple templates.

For example:

fragment itemDetails on Item {
  id
  name
  children{
    children(includeTemplateIDs:"{GUID}"{
      id
      name
      someotherfield
    }
  }
}

You can then leverage the fragment on your query

query GetPageContent($datasource: String!, $contextItem: String!) {
  datasource(value: $datasource) {
    ...itemDetails
 }
 contextItem(value: $contextItem) {
    ...itemDetails
 }

Ps: Please validate this syntax, just guiding on the approach here

1
  • what is "someotherfield" in your sample? As mentioned in my question I don't want to list all the fields in my query. I want the query to return all fields from item's template and all inherited templates except standard fields with __ prefix. – whuu Mar 23 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.