Open AndyMardell opened 3 years ago
You should update the composer package for this, otherwise the module is useless.
I think there is a better solution for this In the file vendor/mageplaza/module-blog-graphql/Model/Resolver/FilterArgument.php The function getEntityAttributes
public function getEntityAttributes(): array
{
$entities = ['Post', 'Topic', 'Category', 'Comment', 'Product'];
$fields = [];
foreach ($entities as $entity) {
/** @var Field $field */
foreach ($this->config->getConfigElement($entity)->getFields() as $field) {
$fields[$field->getName()] = '';
}
}
return array_keys($fields);
}
Returns the array keys But the function getClausesFromAst of the AstConverter class expects the values Changing the return statement from return array_keys($fields); to return $fields; using a plugin fixed the issue for me for all entity types
I think there is a better solution for this In the file vendor/mageplaza/module-blog-graphql/Model/Resolver/FilterArgument.php The function getEntityAttributes
public function getEntityAttributes(): array { $entities = ['Post', 'Topic', 'Category', 'Comment', 'Product']; $fields = []; foreach ($entities as $entity) { /** @var Field $field */ foreach ($this->config->getConfigElement($entity)->getFields() as $field) { $fields[$field->getName()] = ''; } } return array_keys($fields); }
Returns the array keys But the function getClausesFromAst of the AstConverter class expects the values Changing the return statement from return array_keys($fields); to return $fields; using a plugin fixed the issue for me for all entity types
Seams that this only works for the blog part of the queries When you query products there are issues with the filter and the original fix is required
I think there is a better solution for this In the file vendor/mageplaza/module-blog-graphql/Model/Resolver/FilterArgument.php The function getEntityAttributes
public function getEntityAttributes(): array { $entities = ['Post', 'Topic', 'Category', 'Comment', 'Product']; $fields = []; foreach ($entities as $entity) { /** @var Field $field */ foreach ($this->config->getConfigElement($entity)->getFields() as $field) { $fields[$field->getName()] = ''; } } return array_keys($fields); }
Returns the array keys But the function getClausesFromAst of the AstConverter class expects the values Changing the return statement from return array_keys($fields); to return $fields; using a plugin fixed the issue for me for all entity types
Yes, this works for me.
return $fields
instead of return array_keys($fields);
Preconditions
Steps to reproduce
mageplaza/magento-2-blog-extension
andmageplaza/module-blog-graphql
Expected response
Actual response
Error
The actual error in
debug.log
is:main.ERROR: Attribute not found in the visible attributes list {"exception":"[object] (GraphQL\\Error\\Error(code: 0): Attribute not found in the visible attributes list at /var/www/html/vendor/webonyx/graphql-php/src/Error/Error.php:174, LogicException(code: 0): Attribute not found in the visible attributes list at /var/www/html/vendor/magento/framework/GraphQl/Query/Resolver/Argument/AstConverter.php:103)"}
But this (eventually) traces back to
Magento/Framework/GraphQl/Query/Resolver/Argument/FieldEntityAttributesPool.php
at line 39.This line should return an array of product attributes in which we can filter by, but instead, the
attributesInstances['products']
resolver is overridden by this projectsetc/di.xml
file on line 42.This override causes
getEntityAttributesForEntityFromField
to return:When it should return an array similar to:
Temporary fix
If someone needs a temporary fix, you can re-override that di by adding
To your own
[Vendor]\[Module]\etc\di.xml
file.Actual fix
I think lines 42-44 of
etc/di.xml
may have been included by mistake? I'm happy to submit a PR for this but I wanted to check that removing lines 42-44 inetc/di.xml
won't cause other issues.