Похожие чаты

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 ответов

37 просмотров
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.

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта