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

Changed canonical_url to relative_url #398

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function resolve(
if ($urlRewrite) {
$result = [
'id' => $urlRewrite->getEntityId(),
'canonical_url' => $urlRewrite->getTargetPath(),
'relative_url' => $urlRewrite->getTargetPath(),
yogeshsuhagiya marked this conversation as resolved.
Show resolved Hide resolved
'type' => $this->sanitizeType($urlRewrite->getEntityType())
];
}
Expand Down
10 changes: 5 additions & 5 deletions app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.

type Query {
urlResolver(url: String!): EntityUrl @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\EntityUrl") @doc(description: "The urlResolver query returns the relative URL for a specified product, category or CMS page")
}

type EntityUrl @doc(description: "EntityUrl is an output object containing the `id`, `canonical_url`, and `type` attributes") {
yogeshsuhagiya marked this conversation as resolved.
Show resolved Hide resolved
id: Int @doc(description: "The ID assigned to the object associated with the specified url. This could be a product ID, category ID, or page ID.")
canonical_url: String @doc(description: "The internal relative URL. If the specified url is a redirect, the query returns the redirected URL, not the original.")
relative_url: String @doc(description: "The internal relative URL. If the specified url is a redirect, the query returns the redirected URL, not the original.")
type: UrlRewriteEntityTypeEnum @doc(description: "One of PRODUCT, CATEGORY, or CMS_PAGE.")
}

type Query {
urlResolver(url: String!): EntityUrl @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\EntityUrl") @doc(description: "The urlResolver query returns the relative URL for a specified product, category or CMS page")
}

enum UrlRewriteEntityTypeEnum {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp()
}

/**
* Tests if target_path(canonical_url) is resolved for Product entity
* Tests if target_path(relative_url) is resolved for Product entity
*
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
*/
Expand Down Expand Up @@ -60,20 +60,20 @@ public function testProductUrlResolver()
urlResolver(url:"{$urlPath}")
{
id
canonical_url
relative_url
type
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('urlResolver', $response);
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
}

/**
* Tests the use case where canonical_url is provided as resolver input in the Query
* Tests the use case where relative_url is provided as resolver input in the Query
*
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
*/
Expand Down Expand Up @@ -104,15 +104,15 @@ public function testProductUrlWithCanonicalUrlInput()
urlResolver(url:"{$canonicalPath}")
{
id
canonical_url
relative_url
type
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('urlResolver', $response);
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
}

Expand Down Expand Up @@ -147,15 +147,15 @@ public function testCategoryUrlResolver()
urlResolver(url:"{$urlPath2}")
{
id
canonical_url
relative_url
type
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('urlResolver', $response);
$this->assertEquals($categoryId, $response['urlResolver']['id']);
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
}

Expand Down Expand Up @@ -183,14 +183,14 @@ public function testCMSPageUrlResolver()
urlResolver(url:"{$requestPath}")
{
id
canonical_url
relative_url
type
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertEquals($cmsPageId, $response['urlResolver']['id']);
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
$this->assertEquals(strtoupper(str_replace('-', '_', $expectedEntityType)), $response['urlResolver']['type']);
}

Expand Down Expand Up @@ -226,15 +226,15 @@ public function testProductUrlRewriteResolver()
urlResolver(url:"{$urlPath}")
{
id
canonical_url
relative_url
type
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('urlResolver', $response);
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
}

Expand Down Expand Up @@ -266,7 +266,7 @@ public function testInvalidUrlResolverInput()
urlResolver(url:"{$urlPath}")
{
id
canonical_url
relative_url
type
}
}
Expand Down Expand Up @@ -307,15 +307,15 @@ public function testCategoryUrlWithLeadingSlash()
urlResolver(url:"/{$urlPath}")
{
id
canonical_url
relative_url
type
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('urlResolver', $response);
$this->assertEquals($categoryId, $response['urlResolver']['id']);
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
}

Expand Down Expand Up @@ -344,15 +344,15 @@ public function testResolveSlash()
urlResolver(url:"/")
{
id
canonical_url
relative_url
type
}
}
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('urlResolver', $response);
$this->assertEquals($homePageId, $response['urlResolver']['id']);
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
$this->assertEquals('CMS_PAGE', $response['urlResolver']['type']);
}
}