verbb / many-to-many

A Field Type plugin for CraftCMS that allows the management of relationships from both sides
MIT License
83 stars 17 forks source link

GraphQL QueryArgument ":notempty:" not working for many-to-many field #42

Open denisyilmaz opened 1 year ago

denisyilmaz commented 1 year ago

Describe the bug

We have two sections: Organisation Entries and Job Entries. Each Job Entry has a "organisation" relationship field that selects one organisation. In the organisation entry itself we added a many-to-many relationship field called "relatedJobs".

There is no way to filter the organisation entries to only show organisations where the relatedJobs is not empty. Testing this with the built-in relationship field on the job entries this is working without an issue.

Steps to reproduce

  1. create two section types
  2. add on relationship field and one many-to-many relationship field on the entries
  3. query for both with queryargument ":notempty:"
query GetOrganisationsWithJobOffers {
  organisationsEntries(relatedJobs: ":notempty:") {
    ... on EntryInterface {
      title
    }
    ... on organisations_organisation_Entry {
      relatedJobs {
        title
      }
    }
  }
  allOrgEntries: organisationsEntries {
    ... on EntryInterface {
      title
    }
    ... on organisations_organisation_Entry {
      relatedJobs {
        title
      }
    }
  }
  jobsEntries(organisation: ":notempty:") {
    ... on jobs_jobOffer_Entry {
      title
      organisation {
        title
      }
    }
  }
}

Result:

{
  "data": {
    "organisationsEntries": [],
    "allOrgEntries": [
      {
        "title": "Some Organisation",
        "relatedJobs": [
          {
            "title": "Some Job Offer"
          }
        ]
      },
      {
        "title": "Some Other Organisation",
        "relatedJobs": []
      }
    ],
    "jobsEntries": [
      {
        "title": "Some Job Offer",
        "organisation": [
          {
            "title": "Some Organisation"
          }
        ]
      }
    ]
  }
}

Craft CMS version

4.5.6.1

Plugin version

3.0.4

Multi-site?

No

Additional context

No response

engram-design commented 1 year ago

Still looking into this, I'm not sure why, but the arguments aren't even being picked up for the field! But this may very well be related to https://github.com/craftcms/cms/issues/3538