Skip to content

1105 add graphQL schema file creation action #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<separator/>
<!-- Context dependent actions -->
<action id="MagentoCreateAclFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewAclXmlAction"/>
<action id="MagentoCreateGraphQlSchemaFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewGraphQLSchemaAction"/>
<action id="MagentoCreateConfigFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewConfigXmlAction"/>
<action id="MagentoCreateCrontabFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewCrontabXmlAction"/>
<action id="MagentoCreateDiFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewDiXmlAction"/>
Expand Down Expand Up @@ -626,6 +627,7 @@
<internalFileTemplate name="Magento Routes XML"/>
<internalFileTemplate name="Magento Layout XML"/>
<internalFileTemplate name="Magento ACL XML"/>
<internalFileTemplate name="Magento GraphQL Schema"/>
<internalFileTemplate name="Magento Collection Class"/>
<internalFileTemplate name="Magento Model Class"/>
<internalFileTemplate name="Magento Resource Model Class"/>
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions resources/fileTemplates/internal/Magento GraphQL Schema.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<html lang="en">
<body>
<font face="verdana" size="-1">
<p>
The schema.graphqls file defines the basic structure of GraphQL queries and mutations.
</p>
<p>
Read more about <a href="https://devdocs.magento.com/guides/v2.4/graphql/develop/create-graphqls-file.html">Define the GraphQL schema for a module</a>.
</p>
</font>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.context.xml;

import com.intellij.ide.fileTemplates.actions.AttributesDefaults;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.magento.idea.magento2plugin.actions.context.AbstractContextAction;
import com.magento.idea.magento2plugin.magento.files.SchemaGraphQLsFile;
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
import com.magento.idea.magento2plugin.magento.packages.Package;
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
import org.jetbrains.annotations.NotNull;


public class NewGraphQLSchemaAction extends AbstractContextAction {

public static final String ACTION_NAME = "Magento 2 GraphQL Schema File";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 schema.graphqls file";

/**
* New schema.graphqls file action constructor.
*/
public NewGraphQLSchemaAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, SchemaGraphQLsFile.getInstance());
}

@Override
protected boolean isVisible(
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
final PsiDirectory targetDirectory,
final PsiFile targetFile
) {
final PsiDirectory configDir = moduleData.getConfigDir();

if (configDir == null) {
return false;
}

return targetDirectory.getName().equals(Package.moduleBaseAreaDir)
&& targetDirectory.equals(configDir)
&& moduleData.getType().equals(ComponentType.module);
}

@Override
protected AttributesDefaults getProperties(
final @NotNull AttributesDefaults defaults,
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
final PsiDirectory targetDirectory,
final PsiFile targetFile
) {
return defaults;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.magento.files;

import com.intellij.lang.Language;
import com.intellij.lang.jsgraphql.GraphQLLanguage;

public class SchemaGraphQLsFile implements ModuleFileInterface {

public static final String FILE_NAME = "schema.graphqls";

public static final String TEMPLATE = "Magento GraphQL Schema";
private static final SchemaGraphQLsFile INSTANCE = new SchemaGraphQLsFile();

public static SchemaGraphQLsFile getInstance() {
return INSTANCE;
}

@Override
public String getFileName() {
return FILE_NAME;
}

@Override
public String getTemplate() {
return TEMPLATE;
}

@Override
public Language getLanguage() {
return GraphQLLanguage.INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.inspections.graphqls;

import com.magento.idea.magento2plugin.magento.files.GraphQLSchema;
import com.magento.idea.magento2plugin.magento.files.SchemaGraphQLsFile;

public class SchemaResolverInspectionTest extends InspectionGraphqlsFixtureTestCase {

Expand All @@ -22,24 +23,36 @@ protected boolean isWriteActionRequired() {
return false;
}

/**
* Inspection with valid schema resolver.
*/
public void testWithValidSchemaResolverInterface() throws Exception {
myFixture.configureByFile(getFixturePath(GraphQLSchema.FILE_NAME));
myFixture.configureByFile(getFixturePath(SchemaGraphQLsFile.FILE_NAME));
assertHasNoHighlighting(errorMessage);
}

/**
* Inspection with invalid schema resolver.
*/
public void testWithInvalidSchemaResolverInterface() throws Exception {
myFixture.configureByFile(getFixturePath(GraphQLSchema.FILE_NAME));
myFixture.configureByFile(getFixturePath(SchemaGraphQLsFile.FILE_NAME));
assertHasHighlighting(errorMessage);
}

/**
* Inspection with valid batch resolver.
*/
public void testWithValidBatchResolverInterface() throws Exception {
myFixture.configureByFile(getFixturePath(GraphQLSchema.FILE_NAME));
myFixture.configureByFile(getFixturePath(SchemaGraphQLsFile.FILE_NAME));

assertHasNoHighlighting(errorMessage);
}

/**
* Inspection with valid batch service contract resolver.
*/
public void testWithValidBatchServiceContractResolverInterface() throws Exception {
myFixture.configureByFile(getFixturePath(GraphQLSchema.FILE_NAME));
myFixture.configureByFile(getFixturePath(SchemaGraphQLsFile.FILE_NAME));

assertHasNoHighlighting(errorMessage);
}
Expand Down