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

Taxonomy query returns all terms when not set #372

Closed
jacobarriola opened this issue Nov 16, 2020 · 0 comments
Closed

Taxonomy query returns all terms when not set #372

jacobarriola opened this issue Nov 16, 2020 · 0 comments

Comments

@jacobarriola
Copy link
Contributor

Describe the bug
A product attribute is returning all data when a given product is not associated with it instead of null.

I think the issue lies in our resolver when we are setting the values of wc_get_object_terms() to the query args.

Perhaps we should return early if those $term_ids return empty instead of setting the query args to an empty array?

To reproduce
Run the following query, where product with id 123 does not have the Sizes product attribute associated with it and only has Colors.

{
  product(id:123 idType: DATABASE_ID) {
      id
      paSizes {
        nodes {
          name
        }
      }
      paColors {
        nodes {
          name 
        }
      }
    }
}

Expected behavior
paSizes should return null because the given product doesn't have any sizes.

{
  "data": {
    "product": {
        "id": "cHJvZHVjdDo0OTYwNzE=", 
        "paSizes": null,
        "paColors": {
          "nodes": [
            {
              "name": "Blue"
            },
            {
              "name": "Maroon"
            }
          ]
        }
      }
   }
}

Actual behavior
paSizes returns the first 10 sizes.

{
  "data": {
    "product": {
          "id": "cHJvZHVjdDo0OTYwNzE=", 
          "paSizes": {
            "nodes": [
              {
                "name": "W2XL"
              },
              {
                "name": "W2XS"
              },
              {
                "name": "W3XS"
              },
              {
                "name": "WLG"
              },
              {
                "name": "WMD"
              },
              {
                "name": "WSM"
              },
              {
                "name": "WXL"
              },
              {
                "name": "WXS"
              }
            ]
          },
          "paColors": {
            "nodes": [
              {
                "name": "Blue"
              },
              {
                "name": "Maroon"
              }
            ]
          }
        }
    }
}
jacobarriola added a commit to jacobarriola/wp-graphql-woocommerce that referenced this issue Nov 17, 2020
Addresses wp-graphql#372, which prevents returning all data for a given taxonomy when it's not associated with a product.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant