Skip to content

Commit e90daa9

Browse files
author
Vitaliy
authored
Merge branch '1.0.0-develop' into test-inspection-plugin-duplication
2 parents 9ae47b8 + b775fa1 commit e90daa9

File tree

10 files changed

+152
-12
lines changed

10 files changed

+152
-12
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
<internalFileTemplate name="Magento Module Common Php Class"/>
157157
<internalFileTemplate name="Magento Observer Class"/>
158158
<internalFileTemplate name="Magento Module Events Xml"/>
159+
<internalFileTemplate name="Magento GraphQL Resolver Class"/>
159160
</extensions>
160161

161162
<extensions defaultExtensionNs="com.jetbrains.php">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">A resolver performs GraphQL request processing. In general, it is responsible
12+
for constructing a query, fetching data and performing any calculations, then transforming the fetched and
13+
calculated data into a GraphQL array format. Finally, it returns the results wrapped by a callable function.
14+
</font><br>
15+
</td>
16+
</tr>
17+
</table>
18+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
19+
<tr>
20+
<tr>
21+
<td><font face="verdana" size="-1">
22+
<a href="https://devdocs.magento.com/guides/v2.3/graphql/develop/resolvers.html">Read more</a> about GraphQL Resolver, including when those can be used.
23+
</font><br>
24+
</td>
25+
</tr>
26+
</tr>
27+
</table>
28+
</body>
29+
</html>

resources/fileTemplates/code/Magento GraphQL Resolver.php.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

resources/fileTemplates/internal/Magento GraphQL Resolver Class.php.html

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,43 @@
66
-->
77
<html>
88
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">A resolver performs GraphQL request processing. In general, it is responsible
12+
for constructing a query, fetching data and performing any calculations, then transforming the fetched and
13+
calculated data into a GraphQL array format. Finally, it returns the results wrapped by a callable function.
14+
</font><br>
15+
</td>
16+
</tr>
17+
<tr>
18+
<td><font face="verdana" size="-1">A GraphQL resolver must implement interface Magento\Framework\GraphQl\Query\Resolver\BatchResolverInterface.
19+
This interface provides a way to resolve multiple branches/leaves at once (known as batching).
20+
Magento recommends using batch resolvers for queries because they improve performance by fetching information
21+
required to resolve multiple GraphQL requests with a single operation.
22+
</font><br>
23+
</td>
24+
</tr>
25+
<tr>
26+
<td><font face="verdana" size="-1">
27+
<a href="https://devdocs.magento.com/guides/v2.3/graphql/develop/resolvers.html">Read more</a> about GraphQL Resolver, including when those can be used.
28+
</font><br>
29+
</td>
30+
</tr>
31+
</table>
32+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
33+
<tr>
34+
<td colspan="3"><font face="verdana" size="-1">Template's variables:</font></td>
35+
</tr>
36+
<tr>
37+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td>
38+
<td width="10">&nbsp;</td>
39+
<td width="100%" valign="top"><font face="verdana" size="-1">Created PHP GraphQL resolver class namespace.</font></td>
40+
</tr>
41+
<tr>
42+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
43+
<td width="10">&nbsp;</td>
44+
<td width="100%" valign="top"><font face="verdana" size="-1">PHP class for the GraphQL resolver name.</font></td>
45+
</tr>
46+
</table>
947
</body>
10-
</html>
48+
</html>

src/com/magento/idea/magento2plugin/magento/files/GraphQlResolverPhp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class GraphQlResolverPhp implements ModuleFileInterface {
1111
public static String TEMPLATE = "Magento GraphQL Resolver Class";
1212
public static String DEFAULT_DIR = "Model";
13-
public static final String GRAPHQL_RESOLVER_TEMPLATE_NAME = "Magento GraphQL Resolver";
13+
public static final String GRAPHQL_RESOLVER_TEMPLATE_NAME = "Magento GraphQL Resolver Method Resolve";
1414

1515
private String fileName;
1616

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Test;
7+
use Magento\Framework\GraphQl\Query\InvalidInterface;
8+
class <error descr="Class must implements \Magento\Framework\GraphQl\Query\ResolverInterface">InvalidResolverTest</error> implements InvalidInterface
9+
{
10+
}
11+
?>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Test;
7+
class ValidResolverTest implements \Magento\Framework\GraphQl\Query\ResolverInterface
8+
{
9+
}
10+
?>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.inspections.php;
6+
7+
public class GraphQlResolverInspectionTest extends InspectionPhpFixtureTestCase {
8+
9+
@Override
10+
public void setUp() throws Exception {
11+
super.setUp();
12+
myFixture.enableInspections(GraphQlResolverInspection.class);
13+
}
14+
15+
@Override
16+
protected boolean isWriteActionRequired() {
17+
return false;
18+
}
19+
20+
public void testWithInvalidResolverInterface() throws Exception {
21+
myFixture.addFileToProject("schema.graphqls", "type Query {" +
22+
"InvalidResolverTest: InvalidResolver @resolver(class: \"\\\\Magento\\\\Test\\\\InvalidResolverTest\")" +
23+
"}");
24+
myFixture.configureByFile(getFixturePath("InvalidResolverTest.php"));
25+
myFixture.checkHighlighting();
26+
}
27+
28+
public void testWithValidResolverInterface() throws Exception {
29+
myFixture.addFileToProject("schema.graphqls", "type mutation {" +
30+
" ValidResolverTest(): ValidResolver @resolver(class: \"\\\\Magento\\\\Test\\\\ValidResolverTest\")" +
31+
"}");
32+
myFixture.configureByFile(getFixturePath("ValidResolverTest.php"));
33+
myFixture.checkHighlighting();
34+
}
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.magento.idea.magento2plugin.inspections.php;
2+
3+
import com.magento.idea.magento2plugin.BaseProjectTestCase;
4+
5+
import java.io.File;
6+
7+
abstract public class InspectionPhpFixtureTestCase extends BaseProjectTestCase {
8+
9+
private static final String testDataFolderPath = "testData" + File.separator + "inspections" + File.separator;
10+
private static final String fixturesFolderPath = "php" + File.separator;
11+
12+
@Override
13+
protected void setUp() throws Exception {
14+
super.setUp();
15+
myFixture.setTestDataPath(testDataFolderPath);
16+
}
17+
18+
@Override
19+
protected boolean isWriteActionRequired() {
20+
return false;
21+
}
22+
23+
protected String getFixturePath(String fileName) {
24+
return prepareFixturePath(fileName, fixturesFolderPath);
25+
}
26+
}

0 commit comments

Comments
 (0)