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', MagentoStoreModelScopeInterface::SCOPE_STORE);
$viewAllVideosLink = $this->scopeConfig->getValue('google_location_data/google_videos_api/google_videos_view_all_url', MagentoStoreModelScopeInterface::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;
If I do print_r($response) I am getting the correct values.