Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop overwrite tax query filter if it exists #3066

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mohjak
Copy link

@mohjak mohjak commented Mar 4, 2024

What does this implement/fix? Explain your changes.

The change is aggregating the taxonomy filters. This is related to wp-graphql-taxquery plugin.

Does this close any currently open issues?

Any relevant logs, error output, GraphiQL screenshots, etc?

Suppose the following scenario:

Given I installed a fresh copy of a WordPress v6.4.3 and WP GraphQL v1.22.0 and WPGraphQL Tax Query
v0.2.0
And I have created a category with slug 'cat1'
And a tag with slug 'tag1'
And I have created a post that relates only to 'cat1'
When I run the following query:

query categoriesSearch {
  categories(where: {slug: "cat1"}) {
    edges {
      node {
        name
        ... on Category {
          posts(
            first: 1
            where: {status: PUBLISH, taxQuery: {relation: AND, taxArray: [{field: NAME, operator: EXISTS, taxonomy: TAG}]}}
          ) {
            nodes {
              title
              status
              tags {
                nodes {
                  name
                }
              }
            }
          }
        }
      }
    }
  }
}

Then the following result returns:

{
  "data": {
    "categories": {
      "edges": [
        {
          "node": {
            "name": "Cat1",
            "posts": {
              "nodes": [
                {
                  "title": "Post Cat1",
                  "status": "publish",
                  "tags": {
                    "nodes": []
                  }
                }
              ]
            }
          }
        }
      ]
    }
  }
}

But, the expected result is to return nothing in posts.

Any other comments?

Where has this been tested?

Operating System:
Ubuntu 22.04.4 LTS

WordPress Version:
6.4.3

@justlevine
Copy link
Collaborator

Hey @mohjak thanks for opening this PR!

This would be a breaking change to implement, and the same outcome can already be achieved with get_query_arg() and array_merge().

I didn't really follow what issue you're trying to solve with this change, but perhaps it makes more sense to do in your custom code with one of the connection resolver hooks, or if it's a bug with the tax query extensions you referenced then a PR to that repo.

( ref: #3036 (comment) )

@justlevine justlevine added Type: Enhancement New feature or request Status: Discussion Requires a discussion to proceed Compat: Breaking Change This is a breaking change to existing functionality Needs: Info More information is needed to resolve this issue Needs: Reviewer Response This needs the attention of a codeowner or maintainer. labels Mar 4, 2024
@mohjak
Copy link
Author

mohjak commented Mar 5, 2024

Hi @justlevine,

What I am trying to resolve is the following set_query_arg function:

$resolver->set_query_arg(

Which is expecting that there is no tax_query in the query args that coming from graphql input, but actually it can have a tax_query like my above scenario. So, it overwrites the tax_query with the value mentioned in that referenced line of code.

@justlevine
Copy link
Collaborator

Hi @justlevine,

What I am trying to resolve is the following set_query_arg function:

$resolver->set_query_arg(

Which is expecting that there is no tax_query in the query args that coming from graphql input, but actually it can have a tax_query like my above scenario. So, it overwrites the tax_query with the value mentioned in that referenced line of code.

If anything, seems like it would be the resolve you referenced that needs to be "fixed", to check if tax_query is set, and if so merge it and pass the results to the $resolver->set_query_arg().

@mohjak can you foresee any issues if we took that (nonbreaking) approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat: Breaking Change This is a breaking change to existing functionality Needs: Info More information is needed to resolve this issue Needs: Reviewer Response This needs the attention of a codeowner or maintainer. Status: Discussion Requires a discussion to proceed Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants