Schema.graphqls
type Query {
getGoogleMedia: [GoogleMedia] @resolver(class: "Test\\LocationData\\Model\\Resolver\\GoogleMediaResolver")
}
type GoogleMedia {
image_view_all_link: String
images: GooglePhotos
video_view_all_link: String
videos: GoogleVideos
}
type GooglePhotos {
id: Int
review_id: String
image: String
}
type GoogleVideos {
id: Int
review_id: String
video_link: String
}
GoogleMediaResolver
$connection = $this->resourceConnection->getConnection();
$viewAllImagesLink = $this->scopeConfig->getValue('google_location_data/google_photos_api/google_photos_view_all_url', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$viewAllVideosLink = $this->scopeConfig->getValue('google_location_data/google_videos_api/google_videos_view_all_url', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$tableNamePhotos = $connection->getTableName('test_google_photos');
$tableNameVideos = $connection->getTableName('test_google_video');
// Fetch photos
$selectPhotos = $connection->select()
->from($tableNamePhotos, ['id', 'review_id', 'image'])
->where('show_in_website = ?', 1);
$photos = $connection->fetchAll($selectPhotos);
// Fetch videos
$selectVideos = $connection->select()
->from($tableNameVideos, ['id', 'review_id', 'video_link'])
->where('show_in_website = ?', 1);
$videos = $connection->fetchAll($selectVideos);
// Format the response
$response = [
'image_view_all_link' => $viewAllImagesLink,
'images' => $photos,
'video_view_all_link' => $viewAllImagesLink,
'videos' => $videos,
];
// print_r($response);exit;
return $response;
but I am getting null. enter image description here
If I do print_r($response) I am getting the correct values.
-
Can you share the full file for "GoogleMediaResolver" seems something wrong in itGrazitti Dev– Grazitti Dev2024年07月04日 05:40:16 +00:00Commented Jul 4, 2024 at 5:40
-
I figured it out. This issue occur when the return value does not satisfy the structure we defined.NotEqual– NotEqual2024年07月04日 11:50:58 +00:00Commented Jul 4, 2024 at 11:50
2 Answers 2
Use xdebug to identify the issue. I believe no one can tell the problem unless they have access to details like what is the resolver class and how is the complete request flow. I would advise using logging (if xdebug is not possible) to log the data in the resolver and see what value you get. Log other relevant data to understand the issue better.
Here is the correct Schema structure
type Query {
getGoogleMedia: [GoogleMedia] @resolver(class: "Test\\LocationData\\Model\\Resolver\\GoogleDataResolver")
}
type GoogleVideos {
id: Int
review_id: String
video_link: String
}
type GooglePhotos {
view_all_link: String
data: [GooglePhoto]
}
type GoogleVideos {
view_all_link: String
data: [GoogleVideo]
}
type GooglePhoto {
id: Int
review_id: String
image: String
}
type GoogleVideo {
id: Int
review_id: String
video_link: String
}
type getGoogleMedia {
photos: GooglePhotos
videos: GoogleVideos
}