From 3d2630acfc793a27ed0663f83b94de3c15822e0d Mon Sep 17 00:00:00 2001 From: andriysvyryda Date: Fri, 29 Jul 2022 16:40:09 +0300 Subject: [PATCH] Add PWA studio 12 compatibility --- Model/BlogArchiveTypeResolver.php | 31 ++++++++++++ Model/BlogAuthorTypeResolver.php | 31 ++++++++++++ Model/BlogCategoryTypeResolver.php | 31 ++++++++++++ Model/BlogIndexTypeResolver.php | 31 ++++++++++++ Model/BlogPostTypeResolver.php | 31 ++++++++++++ Model/BlogSearchTypeResolver.php | 31 ++++++++++++ Model/BlogTagTypeResolver.php | 31 ++++++++++++ Model/Resolver/DataProvider/Category.php | 2 + Model/Resolver/DataProvider/Post.php | 6 +-- Model/Resolver/Post.php | 3 +- Model/Resolver/Posts.php | 4 +- .../Model/Resolver/EntityUrl.php | 5 +- etc/graphql/di.xml | 50 ++++++++++++++++++- etc/schema.graphqls | 12 ++--- 14 files changed, 286 insertions(+), 13 deletions(-) create mode 100644 Model/BlogArchiveTypeResolver.php create mode 100644 Model/BlogAuthorTypeResolver.php create mode 100644 Model/BlogCategoryTypeResolver.php create mode 100644 Model/BlogIndexTypeResolver.php create mode 100644 Model/BlogPostTypeResolver.php create mode 100644 Model/BlogSearchTypeResolver.php create mode 100644 Model/BlogTagTypeResolver.php diff --git a/Model/BlogArchiveTypeResolver.php b/Model/BlogArchiveTypeResolver.php new file mode 100644 index 0000000..8866d11 --- /dev/null +++ b/Model/BlogArchiveTypeResolver.php @@ -0,0 +1,31 @@ + $categoryData->getId(), + 'category_uid' => $categoryData->getId(), 'category_name' => $categoryData->getTitle(), 'category_level' => $categoryData->getLevel(), 'category_url_key' => $categoryData->getIdentifier(), @@ -162,6 +163,7 @@ public function getDynamicData($category, $fields = null) $categoryData = $category; $breadcrumbs[] = [ 'category_id' => $categoryData->getId(), + 'category_uid' => $categoryData->getId(), 'category_name' => $categoryData->getTitle(), 'category_level' => $categoryData->getLevel(), 'category_url_key' => $categoryData->getIdentifier(), diff --git a/Model/Resolver/DataProvider/Post.php b/Model/Resolver/DataProvider/Post.php index 20951cc..bce92ff 100755 --- a/Model/Resolver/DataProvider/Post.php +++ b/Model/Resolver/DataProvider/Post.php @@ -109,7 +109,7 @@ public function __construct( * @return array * @throws NoSuchEntityException */ - public function getData(string $postId, $fields = null): array + public function getData(string $postId, $fields = null, $storeId = null): array { $post = $this->postRepository->getFactory()->create(); $post->getResource()->load($post, $postId); @@ -121,14 +121,14 @@ public function getData(string $postId, $fields = null): array $data = []; $this->state->emulateAreaCode( Area::AREA_FRONTEND, - function () use ($post, $fields, &$data) { + function () use ($post, $fields, &$data, $storeId) { $themeId = $this->scopeConfig->getValue( 'design/theme/theme_id', ScopeInterface::SCOPE_STORE ); $theme = $this->themeProvider->getThemeById($themeId); $this->design->setDesignTheme($theme, Area::AREA_FRONTEND); - + $post->setStoreId($storeId); $data = $this->getDynamicData($post, $fields); return $data; diff --git a/Model/Resolver/Post.php b/Model/Resolver/Post.php index dbfa7a3..2906869 100755 --- a/Model/Resolver/Post.php +++ b/Model/Resolver/Post.php @@ -44,11 +44,12 @@ public function resolve( array $value = null, array $args = null ) { + $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); $postId = $this->getPostId($args); $fields = $info ? $info->getFieldSelection(10) : null; try { - $postData = $this->postDataProvider->getData($postId, $fields); + $postData = $this->postDataProvider->getData($postId, $fields, $storeId); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); } diff --git a/Model/Resolver/Posts.php b/Model/Resolver/Posts.php index 275a9b4..968ace3 100755 --- a/Model/Resolver/Posts.php +++ b/Model/Resolver/Posts.php @@ -93,6 +93,7 @@ public function resolve( array $value = null, array $args = null ) { + $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); $searchCriteria = $this->searchCriteriaBuilder->build('di_build_magefan_blog_post', $args); $statusFilter = $this->filterBuilder ->setField('is_active') @@ -161,7 +162,8 @@ public function resolve( foreach ($items as $k => $data) { $items[$k] = $this->postDataProvider->getData( $data['post_id'], - isset($fields['items']) ? $fields['items'] : null + isset($fields['items']) ? $fields['items'] : null, + $storeId ); } diff --git a/Plugin/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php b/Plugin/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php index 198782e..f7ac5d8 100644 --- a/Plugin/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php +++ b/Plugin/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php @@ -71,7 +71,10 @@ public function afterResolve( $result = [ 'id' => $blogPage['id'], - 'type' => $type + 'type' => $type, + 'type_id' => $type, + 'relative_url' => $path, + 'redirect_code' => 0 ]; return $result; diff --git a/etc/graphql/di.xml b/etc/graphql/di.xml index 6fe7b60..d279635 100644 --- a/etc/graphql/di.xml +++ b/etc/graphql/di.xml @@ -101,5 +101,53 @@ - + + + + Magefan\BlogGraphQl\Model\BlogIndexTypeResolver + + + + + + + Magefan\BlogGraphQl\Model\BlogPostTypeResolver + + + + + + + Magefan\BlogGraphQl\Model\BlogCategoryTypeResolver + + + + + + + Magefan\BlogGraphQl\Model\BlogTagTypeResolver + + + + + + + Magefan\BlogGraphQl\Model\BlogAuthorTypeResolver + + + + + + + Magefan\BlogGraphQl\Model\BlogArchiveTypeResolver + + + + + + + Magefan\BlogGraphQl\Model\BlogSearchTypeResolver + + + diff --git a/etc/schema.graphqls b/etc/schema.graphqls index db8e793..403f773 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -82,7 +82,7 @@ type EntityUrl @doc(description: "") { } -type blogPostsOutput { +type blogPostsOutput implements RoutableInterface { total_count: Int @doc(description: "") total_pages: Int @doc(description: "") items: [BlogPost] @doc(description: "An array of Blog posts") @@ -98,7 +98,7 @@ type blogCategoriesOutput { items: [BlogCategory] @doc(description: "") } -type BlogPost { +type BlogPost implements RoutableInterface { post_id: Int @doc(description: "Id of the Blog Post") post_url: String @doc(description: "Blog Post URL") identifier: String @doc(description: "URL key of Blog Post") @@ -151,7 +151,7 @@ type BlogPost { relatedproduct_id: Int @doc(description: "Id of the Related Product (This attribute used only in filter)") } -type BlogCategory { +type BlogCategory implements RoutableInterface { category_id: Int @doc(description: "Id of the Blog Post Category") parent_category_id: Int @doc(description: "Id of the Blog Post Parent Category") category_url: String @doc(description: "URL of the Blog Post Category") @@ -182,7 +182,7 @@ type BlogCategory { breadcrumbs: [Breadcrumb] @doc(description: "Breadcrumbs, parent categories info.") } -type BlogTag { +type BlogTag implements RoutableInterface { tag_id: Int @doc(description: "Id of the Blog Post Tag") tag_url: String @doc(description: "URL of Blog Tag") identifier: String @doc(description: "URL key of Blog Tag") @@ -202,7 +202,7 @@ type BlogTag { custom_theme_to: String @doc(description: "Blog Tag Custom theme to") } -type BlogAuthor { +type BlogAuthor implements RoutableInterface { author_id: Int @doc(description: "Id of the Blog Post Author") identifier: String @doc(description: "URL key of Blog Author") title: String @doc(description: "Blog Author title") @@ -237,7 +237,7 @@ input BlogCommentsFilterInput { or: BlogCommentsFilterInput @doc(description: "The keyword required to perform a logical OR comparison") } -type blogCommentsOutput { +type blogCommentsOutput implements RoutableInterface { total_count: Int @doc(description: "") total_pages: Int @doc(description: "") items: [BlogComment] @doc(description: "")