wp-graphql / wp-graphql-tax-query

Adds `tax_query` support to postObject connection queries using WP_Query
46 stars 16 forks source link

Error when trying to filter a CPT by a custom taxonomy via NodeByUri #21

Closed drewbaker closed 3 years ago

drewbaker commented 3 years ago

This query:

query PORTFOLIO_LIST($uri: String! $where: HierarchicalContentNodeToContentNodeConnectionWhereArgs) {
  nodeByUri(uri: $uri) {
    id
    ... on NodeWithTitle {
      title
    }
    ... on PrimaryPage {
      id
      children(where: $where) {
        nodes {
          id
          ... on PrimaryPage {
            title
          }
        }
      }
    }
  }
}

With these var's:

{
  "uri": "/primary/featured-work/",
  "where": {"taxQuery": {"taxArray": {"terms": "featured", "taxonomy": "FILTER", "field": "SLUG"}}}
}

Gives this error:

{
  "errors": [
    {
      "message": "Variable \"$where\" got invalid value {\"taxQuery\":{\"taxArray\":{\"terms\":\"featured\",\"taxonomy\":\"FILTER\",\"field\":\"SLUG\"}}}; Expected type HierarchicalContentNodeToContentNodeConnectionWhereArgsTaxArray to be an object at value.taxQuery.taxArray.terms.",
      "extensions": {
        "category": "graphql"
      },
      "locations": [
        {
          "line": 1,
          "column": 36
        }
      ]
    },
    {
      "message": "Variable \"$where\" got invalid value {\"taxQuery\":{\"taxArray\":{\"terms\":\"featured\",\"taxonomy\":\"FILTER\",\"field\":\"SLUG\"}}}; Expected type HierarchicalContentNodeToContentNodeConnectionWhereArgsTaxArray to be an object at value.taxQuery.taxArray.taxonomy.",
      "extensions": {
        "category": "graphql"
      },
      "locations": [
        {
          "line": 1,
          "column": 36
        }
      ]
    },
    {
      "message": "Variable \"$where\" got invalid value {\"taxQuery\":{\"taxArray\":{\"terms\":\"featured\",\"taxonomy\":\"FILTER\",\"field\":\"SLUG\"}}}; Expected type HierarchicalContentNodeToContentNodeConnectionWhereArgsTaxArray to be an object at value.taxQuery.taxArray.field.",
      "extensions": {
        "category": "graphql"
      },
      "locations": [
        {
          "line": 1,
          "column": 36
        }
      ]
    }
  ]
}

Not it works if I don't pass in the where arg as a var and just hardcode it into the query. What am I doing wrong?

drewbaker commented 3 years ago

It works if I have taxArray as an array in my vars, like this:

  "where": {"taxQuery": {"taxArray": [{"terms": "featured", "taxonomy": "FILTER", "field": "SLUG"}] }}

Weird thing is if I don't use vars, and just code in the taxArray then it works fine. Also the error complaining about terms not being an object threw me off.