Azure / data-api-builder

Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
https://aka.ms/dab/docs
MIT License
873 stars 177 forks source link

[Bug]: array "contains" not supported when using filter #2058

Open jaykar2020 opened 7 months ago

jaykar2020 commented 7 months ago

What happened?

Simplified Schema

type NestedData {
  author: String
  nestedArray: [String]
}

type SomeEntity @model {
  contentId: String
  outsideArray: [String]
  nestedData: [NestedData]
}

Config

"entities": {
    "SomeEntity": {
      "source": "test",
      "rest": false,
      "graphql": true,
      "permissions": [
        {
          "role": "anonymous",
          "actions": [
            "*"
          ]
        }
      ]
    },
    "NestedData": {
      "source": "test",
      "rest": false,
      "graphql": true,
      "permissions": [
        {
          "role": "anonymous",
          "actions": [
            "*"
          ]
        }
      ]
    }
  }

Query

  someEntities(
    first: 5
    filter: {
      and: [
        { nestedData: { author: { eq: "author1" } } }
        { nestedData: { nestedArray: { contains: "item1" } } }
      ]
    }
  ) {
    items {
      contentId,
      outsideArray
      nestedData{
        nestedArray
      }
    }
  }

Output: No Data

{
  "data": {
    "someEntities": {
      "items": []
    }
  }
}

Query

  someEntities(
    first: 5
    filter: {
      and: [
        { nestedData: { author: { eq: "author1" } } }
      ]
    }
  ) {
    items {
      contentId,
      outsideArray
      nestedData{
        nestedArray
      }
    }
  }

Output: Returns Data

{
  "data": {
    "someEntities": {
      "items": [
        {
          "contentId": "Content2",
          "outsideArray": [
            "item1",
            "item2"
          ],
          "nestedData": [
            {
              "nestedArray": [
                "item1",
                "item2"
              ]
            },
            {
              "nestedArray": [
                "item2",
                "item3"
              ]
            },
            {
              "nestedArray": []
            },
            {
              "nestedArray": [
                "item4",
                "item5"
              ]
            }
          ]
        }
      ]
    }
  }
}

Note: Filtering without array contains clause works. However, including array contains (e.g. { nestedData: { nestedArray: { contains: "item1" } } } ) fails for the same data

Version

Microsoft.DataApiBuilder 0.11.6-rc+f557b4da4c350f878d9a44632037daef9349f769

What database are you using?

CosmosDB NoSQL

What hosting model are you using?

Static Web Apps (SWA)

Which API approach are you accessing DAB through?

GraphQL

Relevant log output

{
  "data": {
    "someEntities": {
      "items": []
    }
  }
}

Code of Conduct

jaykar2020 commented 6 months ago

Any update on this? Am I using it wrong?