diff --git a/src/Plugin/GraphQL/EntityQueryBase.php b/src/Plugin/GraphQL/EntityQueryBase.php index 549853b36263730ddbd443e09e9d8047f6f67dee..5edfa9419e418b0d2359ac8c29128b152d98c738 100644 --- a/src/Plugin/GraphQL/EntityQueryBase.php +++ b/src/Plugin/GraphQL/EntityQueryBase.php @@ -228,6 +228,9 @@ class EntityQueryBase extends DataProducerPluginBase implements ContainerFactory $operator = !empty($condition['operator']) ? $condition['operator'] : NULL; $language = !empty($condition['language']) ? $condition['language'] : NULL; + // Map GraphQL operator to proper ConditionInterface operator. + $operator = static::OPERATOR_MAPPING[$operator] ?? NULL; + // We need at least a value or an operator. if (empty($operator) && empty($value)) { throw new UserError(sprintf("Missing value and operator in filter for '%s'.", $field)); @@ -261,11 +264,6 @@ class EntityQueryBase extends DataProducerPluginBase implements ContainerFactory $operator = is_array($value) ? 'IN' : '='; } - // Map GraphQL operator to proper ConditionInterface operator. - if (isset(static::OPERATOR_MAPPING[$operator])) { - $operator = static::OPERATOR_MAPPING[$operator]; - } - // Add the condition for the current field. $group->condition($field, $value, $operator, $language); } diff --git a/tests/src/Kernel/SchemaExtension/EntityQueryExtensionTest.php b/tests/src/Kernel/SchemaExtension/EntityQueryExtensionTest.php index 86aec2350c49974a7f5fcf521c7c3221e5b1972a..047917a27f4948694c174252601fcb5883fe3e5a 100644 --- a/tests/src/Kernel/SchemaExtension/EntityQueryExtensionTest.php +++ b/tests/src/Kernel/SchemaExtension/EntityQueryExtensionTest.php @@ -194,6 +194,51 @@ class EntityQueryExtensionTest extends CoreComposableKernelTestBase { $this->assertEquals($node->label(), $data['label']); } + /** + * Resolves an entity by type with EQUAL operator. + */ + public function testEntityByType(): void { + NodeType::create(['type' => 'article'])->save(); + + $user = $this->setUpCurrentUser(); + $role = $this->createRole(['bypass node access', 'administer taxonomy']); + $user->addRole($role); + $this->setCurrentUser($user); + + $node = Node::create([ + 'type' => 'article', + 'title' => 'Test', + ]); + $node->save(); + + $server = $this->getCoreComposableServerBuilder() + ->enableEntityType('node', [], ['article']) + ->enableExtension('entity_query') + ->enableBaseEntityField('label') + ->enableValueFields() + ->createServer(); + + $query = <<<GQL + query entityQuery { + entityQuery( + entityType: NODE + filter: {conditions: [{field: "type", value: "article", operator: EQUAL}], groups: [], conjunction: AND} + limit: 3 + offset: 0 + ) { + items { + label + } + total + } + } + GQL; + + $result = $server->executeOperation(OperationParams::create(['query' => $query])); + $data = $result->data['entityQuery']; + $this->assertEquals($node->label(), $data['items'][0]['label']); + } + /** * Performs access checks. */