Похожие чаты

I am sorry, I know this is a Javascript group,

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 😭😭

1 ответов

22 просмотра
devFojo-Olubo Автор вопроса

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.

Похожие вопросы

Обсуждают сегодня

Какой-то там пердун в 90-х решил, что есть какая-то разная типизация. Кого вообще это волнует?
КТ315
49
Hi. Do we have a raid bot? Why nobody doing raids on X? Even RH mentioned this and nobody paying attention...whats the channel for hex memes? If mods cant run raids just insta...
H
31
Подскажите, а есть vault lite или ченить такое?) А то нужен вольт для похода в вольт, но весит он ~500 мб) как-то многовато для парочки запросов ))
Alexandr Orloff
17
блеать, почему так?? где в роутере это исправляется?
Маньяков 🇦🇲
16
void terminal_scroll() { memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, buffer_size - VGA_WIDTH); memset(terminal_buffer + buffer_size - VGA_WIDTH, 0, VGA_WIDTH); ...
Егор
47
🌊 Ocean Nodes Dashboard Update 🚀 Hey, Oceaners! First off, a massive round of applause 👏to all of you for the amazing engagement since we launched Ocean Nodes. In just a few ...
KreigDK | Never DM first🌊
3
Всем привет! Подскажите, пожалуйста, в чем ошибка? Настраиваю подключение к MySQL. Либы лежат рядом с exe. Все как по "учебнику"
Евгений
16
А можете как-то проверить меня по знаниям по ассемблеру?
A A
132
Здравствуйте! У меня появилась возможность купить книгу "Изучай Haskell во имя добра!". Но я где-то слышал, что эта книга устарела. Насколько это правда??
E
22
люди, которые используют flameshot, к вам вопрос. Можно-ли поставить хоткей на создание скриншота? В программе есть отдел "горячие клавиши", но там все для редактирования, скр...
ThunDer104
11
Карта сайта