У меня есть этот запрос.
query{
paintInputsUser{
username,country, views, rol
}
}
Однако мне нужен способ конвертировать эти значения в уникальное поле, поиск в Google, я обнаружил, что лучший подход заключается в использовании фрагмента.Я хочу это:
query{
...paintInputsUser
}
, но я не смог найти, как создать фрагмент и как добавить его в схему.
Это мой paintInputsUser Тип
<?php
namespace App\GraphQL\Type;
use App\GraphQL\Support\Type;
use GraphQL;
use DB;
use GraphQL\Type\Definition\ObjectType;
use App\Model\Win\Users;
class PaintInputUser extends ObjectType
{
public function __construct(){
$config = [
'name' => 'PaintInputUser',
'description' => 'Help to know which fields the creation and edition of user are available, and the respective data',
'fields' => function() {
return [
'username' => [
'type' => Type::nonNull(Type::string()),
],
'country' => [
'type' => Type::listOf(Type::string()),
'resolve' => function($person) {
$countries = DB::select('select c.country from win_country c inner join win_user_country uc on uc.id_country = c.id_country inner join win_users u on u.id_user = uc.id_user where u.username = ?',[$person->username]);
$array = array();
foreach($countries as $country){
array_push($array,$country->country);
}
return $array;
}
],
'cards' => [
'type' => Type::listOf(Type::string()),
'resolve' => function($person) {
$cards = DB::select('select c.card from win_cards c
inner join win_user_card_granted ucg on ucg.id_card = c.id_card
inner join win_users u on u.id_user = ucg.id_user
where u.username = ?',[$person->username]);
$array = array();
foreach($cards as $card){
array_push($array,$card->card);
}
return $array;
}
],
'views' => [
'type' => Type::listOf(Type::string()),
'resolve' => function($person) {
$views = DB::select('select vp.view_name from win_views_principal vp
inner join win_user_view_granted uvg on uvg.id_view = vp.id_view_principal
inner join win_users u on u.id_user = uvg.id_user
where u.username = ?',[$person->username]);
$array = array();
foreach($views as $view){
array_push($array,$view->view_name);
}
return $array;
}
],
'rol' => [
'type' => Type::listOf(Type::string()),
'resolve' => function($person) {
$roles = DB::select('select r.rolename from win_roles r
inner join win_user_role ur on ur.id_role = r.id_role
inner join win_users u on u.id_user = ur.id_user
where u.username = ?',[$person->username]);
$array = array();
foreach($roles as $rol){
array_push($array,$rol->rolename);
}
return $array;
}
],
];
}
];
parent::__construct($config);
}
}
Пожалуйста, кто-нибудь объяснит мне, как реализовать фрагмент, содержащий paintInputsUser.