2

I am using JSS with Sitecore 10, and using the GraphQL search query, but I got this error after deploying to Sitecore:

ERROR Error: GraphQL error: Query is too complex to execute. The field with the highest complexity is: Field{name='field', alias='link', arguments=GraphQL.Language.AST.Arguments, directives=GraphQL.Language.AST.Directives, selectionSet=SelectionSet{selections=InlineFragment{typeCondition=NamedType{name=LinkField}, directives=GraphQL.Language.AST.Directives, selections=SelectionSet{selections=Field{name='url', alias='', arguments=GraphQL.Language.AST.Arguments, directives=GraphQL.Language.AST.Directives, selectionSet=SelectionSet{selections=}}, Field{name='linkType', alias='', arguments=GraphQL.Language.AST.Arguments, directives=GraphQL.Language.AST.Directives, selectionSet=SelectionSet{selections=}}, Field{name='text', alias='', arguments=GraphQL.Language.AST.Arguments, directives=GraphQL.Language.AST.Directives, selectionSet=SelectionSet{selections=}}, Field{name='__typename', alias='', arguments=GraphQL.Language.AST.Arguments, directives=GraphQL.Language.AST.Directives, selectionSet=SelectionSet{selections=}}}}, Field{name='__typename', alias='', arguments=GraphQL.Language.AST.Arguments, directives=GraphQL.Language.AST.Directives, selectionSet=SelectionSet{selections=}}}}
    at new t (main.fbe7d52e54c38205dd22.js:1)
    at main.fbe7d52e54c38205dd22.js:1
    at main.fbe7d52e54c38205dd22.js:1
    at Set.forEach (<anonymous>)
    at main.fbe7d52e54c38205dd22.js:1
    at Map.forEach (<anonymous>)
    at e.broadcastQueries (main.fbe7d52e54c38205dd22.js:1)
    at main.fbe7d52e54c38205dd22.js:1
    at Object.next (main.fbe7d52e54c38205dd22.js:1)
    at y (main.fbe7d52e54c38205dd22.js:1)

Although it was working fine in GraphQL UI, I found the reason of the issue but I do not know how to fix it. The reason is a Multilist field because when I removed it, it is working fine in Sitecore.

This my GraphQL query:

query StaggeredInfoCardsSearch($rootItem:String){
  search(fieldsEqual: [{name: "_templatename", value: "detailsPage"}
                                     ],
    rootItem:$rootItem
    ) {
    results {
      items {
        item {
          displayName
          id
          name
          template {
            id
          }
          title: field(name: "title") {
            value
          }
          description: field(name: "description") {
            value
          }
          shortDescription: field(name: "shortDescription") {
            value
          }
          thumbnailImage: field(name: "thumbnailImage") {
            ... on ImageField {
                src(maxWidth: 352,maxHeight:264)
              }
          }
          date: field(name: "date") {
            ... on DateField {
                  formattedDateValue(format:"MMM dd, yyyy, HH:mm")
            }
          }
          link: field(name: "link") {
            ... on LinkField {
              url
              linkType
              text
            }
          }
          file: field(name: "file") {
            ... on FileField {
                url
                title
            }
            }
          category: field(name: "category") {
            value
          }
          location: field(name: "location") {
            value
          }
          socialMediaLinks: field(name: "socialMediaLinks") {
            ... on MultilistField {
                targetItems {
                id
                name
                link: field(name: "link") {
                  ... on LinkField {
                      url
                      linkType
                      text
                      }
                    }
                image: field(name: "image") {
                  ... on ImageField {
                        src
                      }
                  }
                }
            }
          }
        }
      }
      totalCount
    }
  }
}

Any idea about this error?

0
0

I faced the same error in Sitecore 10.1 and the below thing worked out for me!!

Step -1: Start increasing the maxComplexity by 1000 and then if you still get the same error repeat step-1. If you get new maxDepth error "Query is too nested to execute. Depth is.." then go to step-2

Step-2: Start increasing the maxDepth by 2 and then if you still get the same error repeat step-2.

4

In the file "Sitecore.Services.GraphQL.config" located under path_to_sitecore_instance\App_Config\Sitecore\Services.GraphQL you can find these notes and config elements (at least in my current Sitecore 9.3 JSS Sitecore site) on line 82:

 <!--
     COMPLEXITY CONFIGURATION
     It is possible to conduct denial of service attacks by constructing extremely expensive to run GraphQL queries.
     The complexity configuration defeats that by limiting how complex of a query will be run.
                                
     maxDepth: how deep the nesting can go in a query. This is good basic protection. 
     NOTE: maxDepth values less than 15 will prevent /ui from running
                                
     fieldImpact: the average impact of adding a list field to a query (e.g. how many average items it would return)
     maxComplexity: how much total field impact a query can have before it is rejected
     NOTE: with fieldImpact at 2, values of maxComplexity less than 250 will prevent /ui from running
 -->
 <complexityConfiguration type="GraphQL.Validation.Complexity.ComplexityConfiguration, GraphQL">
     <maxDepth>15</maxDepth>
     <maxComplexity>2000</maxComplexity>
     <fieldImpact>2</fieldImpact>
 </complexityConfiguration>

During our implementation we had to slightly increase maxDepth to overcome similar error message we have faced.

In your case, I would definitely increase fieldImpact to 3 or 4. Maybe also play a bit with tweaking and increasing maxComplexity . Combination of increasing these two values should do the trick based on code you have in question.

Note: Those values are there for a reason - not to jeopardize performance - so make sure you change them properly.

You are using GraphQL for search. In these complex scenarios, it would be maybe better to create "Search API" that would use Solr underneath and you would just show results on FE.

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.