Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Return full canonical product URL within product object #7

Merged
merged 3 commits into from
May 22, 2018
Merged

Return full canonical product URL within product object #7

merged 3 commits into from
May 22, 2018

Conversation

austris-argalis
Copy link
Contributor

Description

Added canonical URL to graphql schema along with the necessary resolvers.

Fixed Issues (if relevant)

  1. Return full canonical product URL within product object #2: Return full canonical product URL within product object

Manual testing scenarios

  1. Issue CURL request to a running Magento 2.3 store like this:
    curl -X POST -H "Content-Type: application/json" --data '{"query": "{products(filter: {sku: {neq: \"simple1\"}}) {items {id,canonical_url}}}","variables": [],"operationName": null}' http://magento23.local/graphql
  2. Assert that valid product URLs can be found in the response

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

$fixtureSku = 'p002';
$query = <<<QUERY
{
products(filter: {sku: {eq: "$fixtureSku"}})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please convert this test into web API functional test.

See \Magento\GraphQl\Catalog\ProductViewTest::testQueryAllFieldsSimpleProduct as an example.

use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

class CanonicalUrl implements ResolverInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All classes and methods should be documented.

* @param \Magento\Framework\GraphQl\Config\Element\Field $field
* @param $context
* @param ResolveInfo $info
* @param array|null $value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use @inheritdoc instead of duplicating parent annotations.

use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\TestCase;

class CanonicalUrlTest extends TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, unit tests are optional and should be added only when it makes sense (e.g. when you can test method API without mocks). Since the test is already completed, we can keep it.

@paliarush
Copy link
Contributor

@austris-argalis Thank you for your contribution, feel free to contact me directly regarding requested changes at magentocommeng.slack.com (send an email to [email protected] to join).

@austris-argalis
Copy link
Contributor Author

@paliarush thanks for the review!
Hope it's better now.

@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented May 15, 2018

Hi @austris-argalis
Please sign the Contributor License Agreement so that we can proceed with the merge.

Thank you

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented May 15, 2018

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@paliarush paliarush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks good and can be merged after CLA is signed by @austris-argalis

@magento-engcom-team
Copy link
Contributor

@austris-argalis thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@paliarush
Copy link
Contributor

@austris-argalis the test failed CICD environment, please check this:

Magento\GraphQl\Catalog\ProductViewTest::testQueryAllFieldsSimpleProduct
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://magento.url/index.php/catalog/product/view/_ignore_category/1/id/553/s/simple-product/'
+'http://magento.url/index.php/simple-product.html'

@DanielRuf DanielRuf self-requested a review May 17, 2018 21:08
@austris-argalis
Copy link
Contributor Author

Hello @paliarush

Thanks for the info!
Tried reproducing the problem but cannot really get the same results no matter what.
Is the CI server running some specific configurations I could try and replicate?

Been running tests on a fresh install of 2.3-develop over php 7.1.16 with mysql 5.7.
image

also running full graphql api testsuite does not fail this particular test:
image

@paliarush
Copy link
Contributor

@austris-argalis I cannot reproduce the issue locally either. Some settings must be different on the instance running tests.

With current implementation, the test may still pass, while the public API changes (e.g. if we change URL generation logic).

Let's rewrite the test to compare the URL to predefined static value. Such test would correctly fail if public GraphQL interface changes for some reason. Just take base URL and append "simple-product.html" to it before assertion.

@misha-kotov
Copy link

Approved ✅

@paliarush
Copy link
Contributor

@austris-argalis your PR has been merged, thanks for the contribution, you are the first contributor to Magento's GraphQL track!

@keharper keharper added the duplicate This issue or pull request already exists label May 22, 2018
@keharper keharper removed the duplicate This issue or pull request already exists label May 22, 2018
@keharper
Copy link
Contributor

Added canonical_url to the Products endpoint documentation.

naydav pushed a commit that referenced this pull request Jul 11, 2018
magento-engcom-team pushed a commit that referenced this pull request Jan 19, 2019
magento-engcom-team pushed a commit that referenced this pull request Feb 10, 2019
Update branch 2.3-develop
magento-engcom-team pushed a commit that referenced this pull request Feb 14, 2019
Magento 2.3-develop Latest Pull
magento-engcom-team pushed a commit that referenced this pull request Mar 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants