0

I have the checked my instance and search query is enabled. I am getting the below error when i testing my search query in xGraph Browser

Query

query{
  search(keyword:"smart"){
    results{
      totalCount
    }
  }
}

Response

{
  "data": {
    "search": null
  },
  "errors": [
    {
      "message": "Error trying to resolve search.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "search"
      ],
      "extensions": {
        "code": "KEY_NOT_FOUND"
      }
    }
  ]
}
  • Search query in the config is defined per JSS app, not per Sitecore instance. Is it definitely enabled on the current app that you are testing? – Anastasiya Apr 30 at 13:22
  • I am not creating any JSS app yet, testing some queries on the xGraph Browser – Gaurav Apr 30 at 13:32
  • You need a GraphQL endpoint, which needs to be tied to a JSS app. And then that endpoint can be configured with the Search query. Check out this sample config: sitecore.stackexchange.com/questions/18334/… – Anastasiya Apr 30 at 13:56
  • Are you using Sitecore 9.1+ – Jan Bluemink Apr 30 at 14:18
1

The query would not work on Sitecore 9.1 initial version.

You can use somethings like this:

query{
  search(keyword:"smart" fieldsEqual:[{name:"_fullpath", value:"/sitecore/content/*" }]){
    results{
      totalCount
    }
  }
}

It is necessary to have a fieldsEqual. fixed in JSS 11.0.1

Below \App_Config\Sitecore\Services.GraphQL you can found a sample GraphQL endpoint which suits your version.

For local development you can use this config patch to fix the Authentication, for Sitecore 9.1.

<configuration>
  <sitecore>
    <pipelines>
      <owin.cookieAuthentication.validateIdentity>
        <processor type="Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.ValidateIdentity.ValidateSiteNeutralPaths, Sitecore.Owin.Authentication">
          <siteNeutralPaths hint="list">
            <!-- Adjust the path to your endpoint -->
            <path hint="grapql">/sitecore/api/graph/items/</path>
          </siteNeutralPaths>
        </processor>
      </owin.cookieAuthentication.validateIdentity>
    </pipelines>
  </sitecore>
</configuration>
  • Worth noting that as an additional workaround, if you do not wish to add any config patches like the above, you may simply add ?sc_site=shell to the GraphQL URL. The issue is that you may authenticate to different sites using different auth providers, but without a context site on the API Sitecore is not sure how to determine if you are authenticated or not. Giving it the specific site allows it to use the backend auth logic to test if you are signed in. – Kam Figy Jul 8 at 15:52

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