Skip to content

Commit 57d8908

Browse files
Merge pull request #1 from yogeshsuhagiya/2.3-develop-graphql-PR-yogesh-1
Changed canonical_url to relative_url
2 parents ad4efb8 + e6fb2d7 commit 57d8908

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

app/code/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function resolve(
8282
$result = [
8383
'id' => $urlRewrite->getEntityId(),
8484
'canonical_url' => $urlRewrite->getTargetPath(),
85+
'relative_url' => $urlRewrite->getTargetPath(),
8586
'type' => $this->sanitizeType($urlRewrite->getEntityType())
8687
];
8788
}

app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Copyright © Magento, Inc. All rights reserved.
22
# See COPYING.txt for license details.
33

4-
type EntityUrl @doc(description: "EntityUrl is an output object containing the `id`, `canonical_url`, and `type` attributes") {
5-
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.")
6-
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.")
7-
type: UrlRewriteEntityTypeEnum @doc(description: "One of PRODUCT, CATEGORY, or CMS_PAGE.")
8-
}
9-
104
type Query {
115
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")
126
}
137

8+
type EntityUrl @doc(description: "EntityUrl is an output object containing the `id`, `relative_url`, and `type` attributes") {
9+
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.")
10+
canonical_url: String @deprecated(reason: "The canonical_url field is deprecated, use relative_url instead.")
11+
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.")
12+
type: UrlRewriteEntityTypeEnum @doc(description: "One of PRODUCT, CATEGORY, or CMS_PAGE.")
13+
}
14+
1415
enum UrlRewriteEntityTypeEnum {
1516
}
1617

dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function setUp()
3131
}
3232

3333
/**
34-
* Tests if target_path(canonical_url) is resolved for Product entity
34+
* Tests if target_path(relative_url) is resolved for Product entity
3535
*
3636
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
3737
*/
@@ -60,20 +60,20 @@ public function testProductUrlResolver()
6060
urlResolver(url:"{$urlPath}")
6161
{
6262
id
63-
canonical_url
63+
relative_url
6464
type
6565
}
6666
}
6767
QUERY;
6868
$response = $this->graphQlQuery($query);
6969
$this->assertArrayHasKey('urlResolver', $response);
7070
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
71-
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
71+
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
7272
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
7373
}
7474

7575
/**
76-
* Tests the use case where canonical_url is provided as resolver input in the Query
76+
* Tests the use case where relative_url is provided as resolver input in the Query
7777
*
7878
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
7979
*/
@@ -104,15 +104,15 @@ public function testProductUrlWithCanonicalUrlInput()
104104
urlResolver(url:"{$canonicalPath}")
105105
{
106106
id
107-
canonical_url
107+
relative_url
108108
type
109109
}
110110
}
111111
QUERY;
112112
$response = $this->graphQlQuery($query);
113113
$this->assertArrayHasKey('urlResolver', $response);
114114
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
115-
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
115+
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
116116
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
117117
}
118118

@@ -147,15 +147,15 @@ public function testCategoryUrlResolver()
147147
urlResolver(url:"{$urlPath2}")
148148
{
149149
id
150-
canonical_url
150+
relative_url
151151
type
152152
}
153153
}
154154
QUERY;
155155
$response = $this->graphQlQuery($query);
156156
$this->assertArrayHasKey('urlResolver', $response);
157157
$this->assertEquals($categoryId, $response['urlResolver']['id']);
158-
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
158+
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
159159
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
160160
}
161161

@@ -183,14 +183,14 @@ public function testCMSPageUrlResolver()
183183
urlResolver(url:"{$requestPath}")
184184
{
185185
id
186-
canonical_url
186+
relative_url
187187
type
188188
}
189189
}
190190
QUERY;
191191
$response = $this->graphQlQuery($query);
192192
$this->assertEquals($cmsPageId, $response['urlResolver']['id']);
193-
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
193+
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
194194
$this->assertEquals(strtoupper(str_replace('-', '_', $expectedEntityType)), $response['urlResolver']['type']);
195195
}
196196

@@ -226,15 +226,15 @@ public function testProductUrlRewriteResolver()
226226
urlResolver(url:"{$urlPath}")
227227
{
228228
id
229-
canonical_url
229+
relative_url
230230
type
231231
}
232232
}
233233
QUERY;
234234
$response = $this->graphQlQuery($query);
235235
$this->assertArrayHasKey('urlResolver', $response);
236236
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
237-
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
237+
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
238238
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
239239
}
240240

@@ -266,7 +266,7 @@ public function testInvalidUrlResolverInput()
266266
urlResolver(url:"{$urlPath}")
267267
{
268268
id
269-
canonical_url
269+
relative_url
270270
type
271271
}
272272
}
@@ -307,15 +307,15 @@ public function testCategoryUrlWithLeadingSlash()
307307
urlResolver(url:"/{$urlPath}")
308308
{
309309
id
310-
canonical_url
310+
relative_url
311311
type
312312
}
313313
}
314314
QUERY;
315315
$response = $this->graphQlQuery($query);
316316
$this->assertArrayHasKey('urlResolver', $response);
317317
$this->assertEquals($categoryId, $response['urlResolver']['id']);
318-
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
318+
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
319319
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
320320
}
321321

@@ -344,15 +344,15 @@ public function testResolveSlash()
344344
urlResolver(url:"/")
345345
{
346346
id
347-
canonical_url
347+
relative_url
348348
type
349349
}
350350
}
351351
QUERY;
352352
$response = $this->graphQlQuery($query);
353353
$this->assertArrayHasKey('urlResolver', $response);
354354
$this->assertEquals($homePageId, $response['urlResolver']['id']);
355-
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
355+
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
356356
$this->assertEquals('CMS_PAGE', $response['urlResolver']['type']);
357357
}
358358
}

0 commit comments

Comments
 (0)