From e1f53d45065a6fa292e2213b72a2742f81197a0b Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Wed, 18 Jul 2018 06:50:46 +0000 Subject: [PATCH 1/7] graphql-ce-120: added store configs schema and resolver --- .../Store/StoreConfigsDataProvider.php | 77 +++++++++++++++++ .../Model/Resolver/StoreConfigs.php | 84 +++++++++++++++++++ .../Magento/StoreGraphQl/etc/schema.graphqls | 29 +++++++ 3 files changed, 190 insertions(+) create mode 100644 app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php create mode 100644 app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php new file mode 100644 index 000000000000..4fb7dc9cdbb0 --- /dev/null +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php @@ -0,0 +1,77 @@ +storeConfigManager = $storeConfigManager; + } + + /** + * Get store configs by store codes + * + * @param array $storeCodes + * @return array + */ + public function getStoreConfigsByStoreCodes(array $storeCodes = null) : array + { + $storeConfigs = $this->storeConfigManager->getStoreConfigs($storeCodes); + + return ['items' => $this->hidrateStoreConfigs($storeConfigs)]; + } + + /** + * Transform StoreConfig objects to in array format + * + * @param StoreConfigInterface[] $storeConfigs + * @return array + */ + private function hidrateStoreConfigs(array $storeConfigs) : array + { + $storeConfigsData = []; + /** @var StoreConfigInterface $storeConfig */ + foreach ($storeConfigs as $storeConfig) { + $storeConfigsData[] = [ + 'id' => $storeConfig->getId(), + 'code' => $storeConfig->getCode(), + 'website_id' => $storeConfig->getWebsiteId(), + 'locale' => $storeConfig->getLocale(), + 'base_currency_code' => $storeConfig->getBaseCurrencyCode(), + 'default_display_currency_code' => $storeConfig->getDefaultDisplayCurrencyCode(), + 'timezone' => $storeConfig->getTimezone(), + 'weight_unit' => $storeConfig->getWeightUnit(), + 'base_url' => $storeConfig->getBaseUrl(), + 'base_link_url' => $storeConfig->getBaseLinkUrl(), + 'base_static_url' => $storeConfig->getSecureBaseStaticUrl(), + 'base_media_url' => $storeConfig->getBaseMediaUrl(), + 'secure_base_link_url' => $storeConfig->getSecureBaseLinkUrl(), + 'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(), + 'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl() + ]; + } + + return $storeConfigsData; + } +} diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php new file mode 100644 index 000000000000..e03ab72167f1 --- /dev/null +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php @@ -0,0 +1,84 @@ +valueFactory = $valueFactory; + $this->storeConfigsDataProvider = $storeConfigsDataProvider; + } + + /** + * {@inheritdoc} + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) : Value { + + $storeCodes = $this->getStoreCodes($args); + $storeConfigsData = $this->storeConfigsDataProvider->getStoreConfigsByStoreCodes($storeCodes); + + $result = function () use ($storeConfigsData) { + return !empty($storeConfigsData) ? $storeConfigsData : []; + }; + + return $this->valueFactory->create($result); + } + + /** + * Retrieve store codes + * + * @param array $args + * @return array + * @throws GraphQlInputException + */ + private function getStoreCodes($args) : array + { + if (isset($args['store_codes'])) { + if (is_array($args['store_codes'])) { + return $args['store_codes']; + } + throw new GraphQlInputException(__('"store codes should contain a valid array')); + } + + return null; + } +} diff --git a/app/code/Magento/StoreGraphQl/etc/schema.graphqls b/app/code/Magento/StoreGraphQl/etc/schema.graphqls index 6eea6da8fd6f..67515a01fac9 100644 --- a/app/code/Magento/StoreGraphQl/etc/schema.graphqls +++ b/app/code/Magento/StoreGraphQl/etc/schema.graphqls @@ -1,5 +1,11 @@ # Copyright © Magento, Inc. All rights reserved. # See COPYING.txt for license details. +type Query { + storeConfigs ( + storeCodes: [String] @doc(description: "Store Codes of the store configs") +): StoreConfigs + @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigs") @doc(description: "The products query searches for products that match the criteria specified in the search and filter attributes") +} type Website @doc(description: "The type contains information about a website") { id : Int @doc(description: "The ID number assigned to the website") @@ -9,3 +15,26 @@ type Website @doc(description: "The type contains information about a website") default_group_id : String @doc(description: "The default group id that the website has") is_default : Boolean @doc(description: "Specifies if this is the default website") } + +type StoreConfigs @doc(description: "The Store Configs object") { + items: [StoreConfig] @doc(description: "An array containing store configs") +} + +type StoreConfig @doc(description: "The type contains information about a store config") { + id : Int @doc(description: "The ID number assigned to the store") + code : String @doc(description: "A code assigned to the store to identify it") + website_id : Int @doc(description: "The ID number assigned to the website store belongs") + locale : String @doc(description: "Store locale") + base_currency_code : String @doc(description: "Base currency code") + default_display_currency_code : String @doc(description: "Default display currency code") + timezone : String @doc(description: "Timezone of the store") + weight_unit : String @doc(description: "The unit of weight") + base_url : String @doc(description: "Base URL for the store") + base_link_url : String @doc(description: "Base link URL for the store") + base_static_url : String @doc(description: "Base static URL for the store") + base_media_url : String @doc(description: "Base media URL for the store") + secure_base_url : String @doc(description: "Secure base URL for the store") + secure_base_link_url : String @doc(description: "Secure base link URL for the store") + secure_base_static_url : String @doc(description: "Secure base static URL for the store") + secure_base_media_url : String @doc(description: "Secure base media URL for the store") +} From 5229cd6eed7b5e08174268245f23158513feabd9 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Wed, 18 Jul 2018 19:52:55 +0000 Subject: [PATCH 2/7] graphql-ce-120: added api-functional test fixed resolver and dataprovider --- .../Model/Resolver/Store/StoreConfigsDataProvider.php | 5 ++++- .../Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php | 8 ++++---- app/code/Magento/StoreGraphQl/etc/schema.graphqls | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php index 4fb7dc9cdbb0..0d7ce3aa1555 100644 --- a/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php @@ -39,7 +39,9 @@ public function getStoreConfigsByStoreCodes(array $storeCodes = null) : array { $storeConfigs = $this->storeConfigManager->getStoreConfigs($storeCodes); - return ['items' => $this->hidrateStoreConfigs($storeConfigs)]; + return [ + 'items' => $this->hidrateStoreConfigs($storeConfigs) + ]; } /** @@ -66,6 +68,7 @@ private function hidrateStoreConfigs(array $storeConfigs) : array 'base_link_url' => $storeConfig->getBaseLinkUrl(), 'base_static_url' => $storeConfig->getSecureBaseStaticUrl(), 'base_media_url' => $storeConfig->getBaseMediaUrl(), + 'secure_base_url' => $storeConfig->getSecureBaseUrl(), 'secure_base_link_url' => $storeConfig->getSecureBaseLinkUrl(), 'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(), 'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl() diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php index e03ab72167f1..c1daef97d5c6 100644 --- a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php @@ -70,11 +70,11 @@ public function resolve( * @return array * @throws GraphQlInputException */ - private function getStoreCodes($args) : array + private function getStoreCodes($args) { - if (isset($args['store_codes'])) { - if (is_array($args['store_codes'])) { - return $args['store_codes']; + if (isset($args['storeCodes'])) { + if (is_array($args['storeCodes'])) { + return $args['storeCodes']; } throw new GraphQlInputException(__('"store codes should contain a valid array')); } diff --git a/app/code/Magento/StoreGraphQl/etc/schema.graphqls b/app/code/Magento/StoreGraphQl/etc/schema.graphqls index 67515a01fac9..2b45190c540e 100644 --- a/app/code/Magento/StoreGraphQl/etc/schema.graphqls +++ b/app/code/Magento/StoreGraphQl/etc/schema.graphqls @@ -4,7 +4,7 @@ type Query { storeConfigs ( storeCodes: [String] @doc(description: "Store Codes of the store configs") ): StoreConfigs - @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigs") @doc(description: "The products query searches for products that match the criteria specified in the search and filter attributes") + @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigs") @doc(description: "The store configs query") } type Website @doc(description: "The type contains information about a website") { From af4b258a78a4772d4256b7c6e5912ddf326d93de Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Wed, 18 Jul 2018 19:59:16 +0000 Subject: [PATCH 3/7] graphql-ce-120: added api functional test --- .../Store/StoreConfigsResolverTest.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigsResolverTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigsResolverTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigsResolverTest.php new file mode 100644 index 000000000000..5c3566ffe2e1 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigsResolverTest.php @@ -0,0 +1,107 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + /** + * @magentoApiDataFixture Magento/Store/_files/store.php + */ + public function testStoreConfigsFilteredByStoreCode() + { + $storeCode = 'test'; + /** @var StoreConfigManagerInterface $storeConfigsManager */ + $storeConfigsManager = $this->objectManager->get(StoreConfigManagerInterface::class); + /** @var StoreConfigInterface $storeConfig */ + $storeConfig = current($storeConfigsManager->getStoreConfigs([$storeCode])); + $query + = <<graphQlQuery($query); + $this->assertArrayHasKey('storeConfigs', $response); + $this->assertEquals(1, count($response['storeConfigs']['items'])); + $responseStoreConfig = current($response['storeConfigs']['items']); + $this->assertEquals($storeConfig->getId(), $responseStoreConfig['id']); + $this->assertEquals($storeConfig->getCode(), $responseStoreConfig['code']); + $this->assertEquals($storeConfig->getLocale(), $responseStoreConfig['locale']); + $this->assertEquals($storeConfig->getBaseCurrencyCode(), $responseStoreConfig['base_currency_code']); + $this->assertEquals( + $storeConfig->getDefaultDisplayCurrencyCode(), + $responseStoreConfig['default_display_currency_code'] + ); + $this->assertEquals($storeConfig->getTimezone(), $responseStoreConfig['timezone']); + $this->assertEquals($storeConfig->getWeightUnit(), $responseStoreConfig['weight_unit']); + $this->assertEquals($storeConfig->getBaseUrl(), $responseStoreConfig['base_url']); + $this->assertEquals($storeConfig->getBaseLinkUrl(), $responseStoreConfig['base_link_url']); + $this->assertEquals($storeConfig->getBaseStaticUrl(), $responseStoreConfig['base_static_url']); + $this->assertEquals($storeConfig->getBaseMediaUrl(), $responseStoreConfig['base_media_url']); + $this->assertEquals($storeConfig->getSecureBaseUrl(), $responseStoreConfig['secure_base_url']); + $this->assertEquals($storeConfig->getSecureBaseLinkUrl(), $responseStoreConfig['secure_base_link_url']); + $this->assertEquals($storeConfig->getSecureBaseStaticUrl(), $responseStoreConfig['secure_base_static_url']); + $this->assertEquals($storeConfig->getSecureBaseMediaUrl(), $responseStoreConfig['secure_base_media_url']); + } + + /** + * @magentoApiDataFixture Magento/Store/_files/store.php + */ + public function testGetStoreConfigsWithoutStoreCodes() + { + $query + = <<graphQlQuery($query); + $this->assertArrayHasKey('storeConfigs', $response); + $this->assertEquals(2, count($response['storeConfigs']['items'])); + } +} From 3b64955757358d8c1d5f81859870bd1d84d2ac7b Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Thu, 19 Jul 2018 06:46:16 +0000 Subject: [PATCH 4/7] graphql-ce-120: added missing dependency to composer json --- app/code/Magento/StoreGraphQl/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/StoreGraphQl/composer.json b/app/code/Magento/StoreGraphQl/composer.json index 91f79b39c023..d03d759babd2 100644 --- a/app/code/Magento/StoreGraphQl/composer.json +++ b/app/code/Magento/StoreGraphQl/composer.json @@ -4,7 +4,8 @@ "type": "magento2-module", "require": { "php": "~7.1.3||~7.2.0", - "magento/framework": "*" + "magento/framework": "*", + "magento/module-store": "*" }, "suggest": { "magento/module-graph-ql": "*", From b5a2a983c5b8441b8733f2d36055a4fb4f79a1f3 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Thu, 19 Jul 2018 10:22:50 +0000 Subject: [PATCH 5/7] graphql-ce-120: fixed resolver name --- .../Resolver/{StoreConfigs.php => StoreConfigsResolver.php} | 2 +- app/code/Magento/StoreGraphQl/etc/schema.graphqls | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/code/Magento/StoreGraphQl/Model/Resolver/{StoreConfigs.php => StoreConfigsResolver.php} (97%) diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigsResolver.php similarity index 97% rename from app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php rename to app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigsResolver.php index c1daef97d5c6..609985b48e2b 100644 --- a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigs.php +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigsResolver.php @@ -18,7 +18,7 @@ /** * StoreConfig page field resolver, used for GraphQL request processing. */ -class StoreConfigs implements ResolverInterface +class StoreConfigsResolver implements ResolverInterface { /** * @var StoreConfigsDataProvider diff --git a/app/code/Magento/StoreGraphQl/etc/schema.graphqls b/app/code/Magento/StoreGraphQl/etc/schema.graphqls index 2b45190c540e..d0597de04b66 100644 --- a/app/code/Magento/StoreGraphQl/etc/schema.graphqls +++ b/app/code/Magento/StoreGraphQl/etc/schema.graphqls @@ -4,7 +4,7 @@ type Query { storeConfigs ( storeCodes: [String] @doc(description: "Store Codes of the store configs") ): StoreConfigs - @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigs") @doc(description: "The store configs query") + @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigsResolver") @doc(description: "The store configs query") } type Website @doc(description: "The type contains information about a website") { From e85a6e54ee15d8ea808d434b05eb9c666cdd772a Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Thu, 19 Jul 2018 19:26:42 +0000 Subject: [PATCH 6/7] graphql-ce-120: get single store config instead multiple --- .../Store/StoreConfigDataProvider.php | 94 +++++++++++++++++++ .../Store/StoreConfigsDataProvider.php | 80 ---------------- .../Model/Resolver/StoreConfigResolver.php | 63 +++++++++++++ .../Model/Resolver/StoreConfigsResolver.php | 84 ----------------- .../Magento/StoreGraphQl/etc/schema.graphqls | 9 +- ...erTest.php => StoreConfigResolverTest.php} | 74 ++++++--------- 6 files changed, 189 insertions(+), 215 deletions(-) create mode 100644 app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php delete mode 100644 app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php create mode 100644 app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php delete mode 100644 app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigsResolver.php rename dev/tests/api-functional/testsuite/Magento/GraphQl/Store/{StoreConfigsResolverTest.php => StoreConfigResolverTest.php} (58%) diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php new file mode 100644 index 000000000000..0252d7898bee --- /dev/null +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php @@ -0,0 +1,94 @@ +storeConfigManager = $storeConfigManager; + $this->storeResolver = $storeResolver; + $this->storeRepository = $storeRepository; + } + + /** + * Get store config for current store + * + * @return array + */ + public function getStoreConfig() : array + { + $storeId = $this->storeResolver->getCurrentStoreId(); + $store = $this->storeRepository->getById($storeId); + $storeConfig = current($this->storeConfigManager->getStoreConfigs([$store->getCode()])); + + return $this->hidrateStoreConfig($storeConfig); + } + + /** + * Transform StoreConfig object to in array format + * + * @param StoreConfigInterface $storeConfig + * @return array + */ + private function hidrateStoreConfig($storeConfig): array + { + /** @var StoreConfigInterface $storeConfig */ + $storeConfigData = [ + 'id' => $storeConfig->getId(), + 'code' => $storeConfig->getCode(), + 'website_id' => $storeConfig->getWebsiteId(), + 'locale' => $storeConfig->getLocale(), + 'base_currency_code' => $storeConfig->getBaseCurrencyCode(), + 'default_display_currency_code' => $storeConfig->getDefaultDisplayCurrencyCode(), + 'timezone' => $storeConfig->getTimezone(), + 'weight_unit' => $storeConfig->getWeightUnit(), + 'base_url' => $storeConfig->getBaseUrl(), + 'base_link_url' => $storeConfig->getBaseLinkUrl(), + 'base_static_url' => $storeConfig->getSecureBaseStaticUrl(), + 'base_media_url' => $storeConfig->getBaseMediaUrl(), + 'secure_base_url' => $storeConfig->getSecureBaseUrl(), + 'secure_base_link_url' => $storeConfig->getSecureBaseLinkUrl(), + 'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(), + 'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl() + ]; + + return $storeConfigData; + } +} diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php b/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php deleted file mode 100644 index 0d7ce3aa1555..000000000000 --- a/app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php +++ /dev/null @@ -1,80 +0,0 @@ -storeConfigManager = $storeConfigManager; - } - - /** - * Get store configs by store codes - * - * @param array $storeCodes - * @return array - */ - public function getStoreConfigsByStoreCodes(array $storeCodes = null) : array - { - $storeConfigs = $this->storeConfigManager->getStoreConfigs($storeCodes); - - return [ - 'items' => $this->hidrateStoreConfigs($storeConfigs) - ]; - } - - /** - * Transform StoreConfig objects to in array format - * - * @param StoreConfigInterface[] $storeConfigs - * @return array - */ - private function hidrateStoreConfigs(array $storeConfigs) : array - { - $storeConfigsData = []; - /** @var StoreConfigInterface $storeConfig */ - foreach ($storeConfigs as $storeConfig) { - $storeConfigsData[] = [ - 'id' => $storeConfig->getId(), - 'code' => $storeConfig->getCode(), - 'website_id' => $storeConfig->getWebsiteId(), - 'locale' => $storeConfig->getLocale(), - 'base_currency_code' => $storeConfig->getBaseCurrencyCode(), - 'default_display_currency_code' => $storeConfig->getDefaultDisplayCurrencyCode(), - 'timezone' => $storeConfig->getTimezone(), - 'weight_unit' => $storeConfig->getWeightUnit(), - 'base_url' => $storeConfig->getBaseUrl(), - 'base_link_url' => $storeConfig->getBaseLinkUrl(), - 'base_static_url' => $storeConfig->getSecureBaseStaticUrl(), - 'base_media_url' => $storeConfig->getBaseMediaUrl(), - 'secure_base_url' => $storeConfig->getSecureBaseUrl(), - 'secure_base_link_url' => $storeConfig->getSecureBaseLinkUrl(), - 'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(), - 'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl() - ]; - } - - return $storeConfigsData; - } -} diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php new file mode 100644 index 000000000000..8e5bf0120b8b --- /dev/null +++ b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php @@ -0,0 +1,63 @@ +valueFactory = $valueFactory; + $this->storeConfigDataProvider = $storeConfigsDataProvider; + } + + /** + * {@inheritdoc} + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) : Value { + + $storeConfigData = $this->storeConfigDataProvider->getStoreConfig(); + + $result = function () use ($storeConfigData) { + return !empty($storeConfigData) ? $storeConfigData : []; + }; + + return $this->valueFactory->create($result); + } +} diff --git a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigsResolver.php b/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigsResolver.php deleted file mode 100644 index 609985b48e2b..000000000000 --- a/app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigsResolver.php +++ /dev/null @@ -1,84 +0,0 @@ -valueFactory = $valueFactory; - $this->storeConfigsDataProvider = $storeConfigsDataProvider; - } - - /** - * {@inheritdoc} - */ - public function resolve( - Field $field, - $context, - ResolveInfo $info, - array $value = null, - array $args = null - ) : Value { - - $storeCodes = $this->getStoreCodes($args); - $storeConfigsData = $this->storeConfigsDataProvider->getStoreConfigsByStoreCodes($storeCodes); - - $result = function () use ($storeConfigsData) { - return !empty($storeConfigsData) ? $storeConfigsData : []; - }; - - return $this->valueFactory->create($result); - } - - /** - * Retrieve store codes - * - * @param array $args - * @return array - * @throws GraphQlInputException - */ - private function getStoreCodes($args) - { - if (isset($args['storeCodes'])) { - if (is_array($args['storeCodes'])) { - return $args['storeCodes']; - } - throw new GraphQlInputException(__('"store codes should contain a valid array')); - } - - return null; - } -} diff --git a/app/code/Magento/StoreGraphQl/etc/schema.graphqls b/app/code/Magento/StoreGraphQl/etc/schema.graphqls index d0597de04b66..af79d0e3e28b 100644 --- a/app/code/Magento/StoreGraphQl/etc/schema.graphqls +++ b/app/code/Magento/StoreGraphQl/etc/schema.graphqls @@ -1,10 +1,7 @@ # Copyright © Magento, Inc. All rights reserved. # See COPYING.txt for license details. type Query { - storeConfigs ( - storeCodes: [String] @doc(description: "Store Codes of the store configs") -): StoreConfigs - @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigsResolver") @doc(description: "The store configs query") + storeConfig : StoreConfig @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigResolver") @doc(description: "The store config query") } type Website @doc(description: "The type contains information about a website") { @@ -16,10 +13,6 @@ type Website @doc(description: "The type contains information about a website") is_default : Boolean @doc(description: "Specifies if this is the default website") } -type StoreConfigs @doc(description: "The Store Configs object") { - items: [StoreConfig] @doc(description: "An array containing store configs") -} - type StoreConfig @doc(description: "The type contains information about a store config") { id : Int @doc(description: "The ID number assigned to the store") code : String @doc(description: "A code assigned to the store to identify it") diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigsResolverTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php similarity index 58% rename from dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigsResolverTest.php rename to dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php index 5c3566ffe2e1..df86519ae3d1 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigsResolverTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php @@ -9,13 +9,15 @@ use Magento\Store\Api\Data\StoreConfigInterface; use Magento\Store\Api\StoreConfigManagerInterface; +use Magento\Store\Api\StoreRepositoryInterface; +use Magento\Store\Api\StoreResolverInterface; use Magento\TestFramework\ObjectManager; use Magento\TestFramework\TestCase\GraphQlAbstract; /** * Test the GraphQL endpoint's StoreConfigs query */ -class StoreConfigsResolverTest extends GraphQlAbstract +class StoreConfigResolverTest extends GraphQlAbstract { /** @var ObjectManager */ @@ -29,17 +31,22 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Store/_files/store.php */ - public function testStoreConfigsFilteredByStoreCode() + public function testGetStoreConfig() { - $storeCode = 'test'; /** @var StoreConfigManagerInterface $storeConfigsManager */ $storeConfigsManager = $this->objectManager->get(StoreConfigManagerInterface::class); + /** @var StoreResolverInterface $storeResolver */ + $storeResolver = $this->objectManager->get(StoreResolverInterface::class); + /** @var StoreRepositoryInterface $storeRepository */ + $storeRepository = $this->objectManager->get(StoreRepositoryInterface::class); + $storeId = $storeResolver->getCurrentStoreId(); + $store = $storeRepository->getById($storeId); /** @var StoreConfigInterface $storeConfig */ - $storeConfig = current($storeConfigsManager->getStoreConfigs([$storeCode])); + $storeConfig = current($storeConfigsManager->getStoreConfigs([$store->getCode()])); $query = <<graphQlQuery($query); - $this->assertArrayHasKey('storeConfigs', $response); - $this->assertEquals(1, count($response['storeConfigs']['items'])); - $responseStoreConfig = current($response['storeConfigs']['items']); - $this->assertEquals($storeConfig->getId(), $responseStoreConfig['id']); - $this->assertEquals($storeConfig->getCode(), $responseStoreConfig['code']); - $this->assertEquals($storeConfig->getLocale(), $responseStoreConfig['locale']); - $this->assertEquals($storeConfig->getBaseCurrencyCode(), $responseStoreConfig['base_currency_code']); + $this->assertArrayHasKey('storeConfig', $response); + $this->assertEquals($storeConfig->getId(), $response['storeConfig']['id']); + $this->assertEquals($storeConfig->getCode(), $response['storeConfig']['code']); + $this->assertEquals($storeConfig->getLocale(), $response['storeConfig']['locale']); + $this->assertEquals($storeConfig->getBaseCurrencyCode(), $response['storeConfig']['base_currency_code']); $this->assertEquals( $storeConfig->getDefaultDisplayCurrencyCode(), - $responseStoreConfig['default_display_currency_code'] + $response['storeConfig']['default_display_currency_code'] ); - $this->assertEquals($storeConfig->getTimezone(), $responseStoreConfig['timezone']); - $this->assertEquals($storeConfig->getWeightUnit(), $responseStoreConfig['weight_unit']); - $this->assertEquals($storeConfig->getBaseUrl(), $responseStoreConfig['base_url']); - $this->assertEquals($storeConfig->getBaseLinkUrl(), $responseStoreConfig['base_link_url']); - $this->assertEquals($storeConfig->getBaseStaticUrl(), $responseStoreConfig['base_static_url']); - $this->assertEquals($storeConfig->getBaseMediaUrl(), $responseStoreConfig['base_media_url']); - $this->assertEquals($storeConfig->getSecureBaseUrl(), $responseStoreConfig['secure_base_url']); - $this->assertEquals($storeConfig->getSecureBaseLinkUrl(), $responseStoreConfig['secure_base_link_url']); - $this->assertEquals($storeConfig->getSecureBaseStaticUrl(), $responseStoreConfig['secure_base_static_url']); - $this->assertEquals($storeConfig->getSecureBaseMediaUrl(), $responseStoreConfig['secure_base_media_url']); - } - - /** - * @magentoApiDataFixture Magento/Store/_files/store.php - */ - public function testGetStoreConfigsWithoutStoreCodes() - { - $query - = <<graphQlQuery($query); - $this->assertArrayHasKey('storeConfigs', $response); - $this->assertEquals(2, count($response['storeConfigs']['items'])); + $this->assertEquals($storeConfig->getTimezone(), $response['storeConfig']['timezone']); + $this->assertEquals($storeConfig->getWeightUnit(), $response['storeConfig']['weight_unit']); + $this->assertEquals($storeConfig->getBaseUrl(), $response['storeConfig']['base_url']); + $this->assertEquals($storeConfig->getBaseLinkUrl(), $response['storeConfig']['base_link_url']); + $this->assertEquals($storeConfig->getBaseStaticUrl(), $response['storeConfig']['base_static_url']); + $this->assertEquals($storeConfig->getBaseMediaUrl(), $response['storeConfig']['base_media_url']); + $this->assertEquals($storeConfig->getSecureBaseUrl(), $response['storeConfig']['secure_base_url']); + $this->assertEquals($storeConfig->getSecureBaseLinkUrl(), $response['storeConfig']['secure_base_link_url']); + $this->assertEquals( + $storeConfig->getSecureBaseStaticUrl(), + $response['storeConfig']['secure_base_static_url'] + ); + $this->assertEquals($storeConfig->getSecureBaseMediaUrl(), $response['storeConfig']['secure_base_media_url']); } } From 8f3c6e920b7bdb953c31013c843017a4d25e3ed6 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Mon, 23 Jul 2018 06:38:07 +0000 Subject: [PATCH 7/7] graphql-ce-120: fixed api functional test for store config --- .../GraphQl/Store/StoreConfigResolverTest.php | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php index df86519ae3d1..4657a1e763ae 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php @@ -47,24 +47,22 @@ public function testGetStoreConfig() = <<