0

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.

asked Jul 4, 2024 at 3:53
2
  • Can you share the full file for "GoogleMediaResolver" seems something wrong in it Commented Jul 4, 2024 at 5:40
  • I figured it out. This issue occur when the return value does not satisfy the structure we defined. Commented Jul 4, 2024 at 11:50

2 Answers 2

0

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.

answered Jul 4, 2024 at 5:44
0

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
}
answered Jul 4, 2024 at 11:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.