but I need help with a php code.
                  
                  
                  <?php
                  
                  
                  
                  
                  
                  declare(strict_types=1);
                  
                  
                  
                  
                  
                  namespace src\Types;
                  
                  
                  
                  
                  
                  use GraphQL\Type\Definition\ListOfType;
                  
                  
                  use GraphQL\Type\Definition\ObjectType;
                  
                  
                  use GraphQL\Type\Definition\Type;
                  
                  
                  use src\Models\CategoryModel;
                  
                  
                  use src\Utils\Logger;
                  
                  
                  use src\Utils\TypeRegistry;
                  
                  
                  use Throwable;
                  
                  
                  
                  
                  
                  class QueryType extends ObjectType
                  
                  
                  {
                  
                  
                   public function __construct()
                  
                  
                   {
                  
                  
                    parent::__construct([
                  
                  
                     'name' => "Query",
                  
                  
                     "fields" => [
                  
                  
                      "categories" => [
                  
                  
                       "type" => new ListOfType(TypeRegistry::getType(CategoryType::class)),
                  
                  
                       "description" => "This returns all categories",
                  
                  
                       "resolve" => static function (): array {
                  
                  
                        try {
                  
                  
                         // Logger::dumpDie([CategoryModel::getAll()]);
                  
                  
                         var_dump(CategoryModel::getAll());
                  
                  
                         return CategoryModel::getAll();
                  
                  
                        } catch (Throwable $e) {
                  
                  
                         Logger::dumpDie([$e->getMessage(), $e->getFile(), $e->getLine()]);
                  
                  
                        }
                  
                  
                       }
                  
                  
                      ]
                  
                  
                     ]
                  
                  
                    ]);
                  
                  
                   }
                  
                  
                  }
                  
                  
                  
                  
                  
                  <?php
                  
                  
                  
                  
                  
                  declare(strict_types=1);
                  
                  
                  
                  
                  
                  namespace src\Types;
                  
                  
                  
                  
                  
                  use GraphQL\Type\Definition\NonNull;
                  
                  
                  use GraphQL\Type\Definition\ObjectType;
                  
                  
                  use GraphQL\Type\Definition\Type;
                  
                  
                  
                  
                  
                  class CategoryType extends ObjectType
                  
                  
                  {
                  
                  
                   public function __construct()
                  
                  
                   {
                  
                  
                    parent::__construct([
                  
                  
                     'name' => "Category",
                  
                  
                     "description" => "Type for product categories",
                  
                  
                     'fields' => static fn (): array => [
                  
                  
                      "name" => new NonNull(Type::string()),
                  
                  
                     ]
                  
                  
                    ]);
                  
                  
                   }
                  
                  
                  }
                  
                  
                  
                  
                  
                  The thing is the CategoryModel actually returns the correct data 
                  
                  
                  
                  
                  
                  array(3) {
                  
                  
                    [0]=>
                  
                  
                    array(1) {
                  
                  
                      ["name"]=>
                  
                  
                      string(3) "all"
                  
                  
                    }
                  
                  
                    [1]=>
                  
                  
                    array(1) {
                  
                  
                      ["name"]=>
                  
                  
                      string(7) "clothes"
                  
                  
                    }
                  
                  
                    [2]=>
                  
                  
                    array(1) {
                  
                  
                      ["name"]=>
                  
                  
                      string(4) "tech"
                  
                  
                    }
                  
                  
                  }
                  
                  
                  
                  
                  
                  But for some reasons, the resolver for Categories believes the returned data is not the same with the one declared in CategoryType
                  
                  
                  
                  
                  
                  {"errors":[{"message":"Internal server error","locations":[{"line":2,"column":5}],"path":["categories",0]},{"message":"Internal server error","locations":[{"line":2,"column":5}],"path":["categories",1]},{"message":"Internal server error","locations":[{"line":2,"column":5}],"path":["categories",2]}],"data":{"categories":[null,null,null]}}
                  
                  
                  
                  
                  
                  If I change the type to string, and I return string, the query goes true, but change it to CategoryType, it bugs out.
                  
                  
                  
                  
                  
                  Don't know if any can please help me out 😭😭
                  
                  
                
Ok so I just discovered that the returned data is null (even though the logged function returns the correct data). Still don't know why.
Обсуждают сегодня