drupal-graphql / graphql-search-api

GraphQL & Drupal Search API integration.
10 stars 22 forks source link

Not equal to (<>) operator on condition does not allow for NULL value #39

Closed astowell-adk closed 3 years ago

astowell-adk commented 3 years ago

I'm trying to query for any items in an index that do not have a null string field. I have found that because the value field is required for the ConditionInput I cannot accomplish this. I have tested making the value field in the ConditionInput optional and that does allow me to query for items where a given field is null.

Below is a working example after I modified the Drupal\graphql_search_api\Plugin\GraphQL\InputTypes\ConditionInput.php file

query{
  searchAPISearch(
    index_id:"default_solr_index",
    conditions: [{
      operator: "<>"
      name: "field_my_field"
    }]) {
    result_count
    documents {
      ... on DefaultSolrIndexDoc {
        nid
        title
        field_my_field
      }
    }
  }
}

I edited the ConditionInput.php file to look like

<?php

namespace Drupal\graphql_search_api\Plugin\GraphQL\InputTypes;

use Drupal\graphql\Plugin\GraphQL\InputTypes\InputTypePluginBase;

/**
 * Condition input type.
 *
 * @GraphQLInputType(
 *   id = "condition_input",
 *   name = "ConditionInput",
 *   fields = {
 *     "name" = "String!",
 *     "value" = "String",
 *     "operator" = "String"
 *   }
 * )
 */
class ConditionInput extends InputTypePluginBase {

}

Is there a different way I can query for an item without a null field value, or is this a bug?

duartegarin commented 3 years ago

Have you tried the string "NULL" in the value field?

astowell-adk commented 3 years ago

I did, but that did not give me the results I wanted (field being null). It appeared to just search for the string "NULL" in the field.

carolpettirossi commented 3 years ago

@astowell-adk, Can you please give me an example of when a field is indexed as 'null'? Just so I can replicate and test your suggestion.

Or do you mean fields that are not actually indexed, for example, field_category empty on an article is not added to the index document?

astowell-adk commented 3 years ago

@carolpettirossi here's the specific scenario:

carolpettirossi commented 3 years ago

Thanks for the quick reply @astowell-adk. I could reproduce what you mean and the change on ConditionInput does fix the issue. I'll add that to the code and release a new graphql_search_api soon.

astowell-adk commented 3 years ago

@carolpettirossi thank you so much!