Sitecore / jss

Software development kit for JavaScript developers building web applications with Sitecore Experience Platform
https://jss.sitecore.com
Apache License 2.0
263 stars 275 forks source link

GraphQL query on Edge #1913

Closed craighicks13 closed 2 months ago

craighicks13 commented 2 months ago

Describe the Bug

I’m not sure anyone else found this issue using GraphQL on the Edge.

This graphql query works fine locally (docker):

query ConsultantsBucket(
  $bucket: String
  $locale: String!
  $start: String!
  $amount: Int!
) {
  search(
    where: {
      AND: [
        { name: "_path", value: $bucket, operator: EQ }
        { name: "_language", value: $locale, operator: EQ }
        { name: "personIsActive", value: "1", operator: EQ }
      ]
    }
    first: $amount
    after: $start
    orderBy: { name: "personLastName", direction: ASC }
  ) {
    total
    results {
      url {
        path
      }
      updated: field(name: "__Updated") {
        value
      }
      changeFrequency: field(name: "ChangeFrequency") {
        jsonValue
      }
      priority: field(name: "Priority") {
        jsonValue
      }
    }
    pageInfo {
      hasNext
      endCursor
    }
  }

But when I push to the edge, I get this error:

{
  "errors": [
    {
      "message": "Argument \"where\" has invalid value",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "search"
      ]
    }
  ],
  "data": {
    "search": null
  }
}

To Reproduce

When it's the last item in the conditional array, I get the error: { name: "personIsActive", value: "1", operator: EQ } This is also true of any template field I add, like"personLastName".

Once I make sure the template field isn’t the last item in my search conditions array it works.

query ConsultantsBucket(
  $bucket: String
  $locale: String!
  $start: String!
  $amount: Int!
) {
  search(
    where: {
      AND: [
        { name: "_path", value: $bucket, operator: EQ }
        { name: "personIsActive", value: "1", operator: EQ }
        { name: "_language", value: $locale, operator: EQ }
      ]
    }
    first: $amount
    after: $start
    orderBy: { name: "personLastName", direction: ASC }
  ) {
    total
    results {
      url {
        path
      }
      updated: field(name: "__Updated") {
        value
      }
      changeFrequency: field(name: "ChangeFrequency") {
        jsonValue
      }
      priority: field(name: "Priority") {
        jsonValue
      }
    }
    pageInfo {
      hasNext
      endCursor
    }
  }

Expected Behavior

I would expect it to work fine regardless of the order of the conditional objects, especially since it work locally in the docker setup.

Possible Fix

May be a something with parsing the query?

Provide environment information

craighicks13 commented 2 months ago

Wrong place for this