diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index 5e59edae9..a75fbd09a 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -60,6 +60,7 @@
+ The schema.graphqls file defines the basic structure of GraphQL queries and mutations. +
++ Read more about Define the GraphQL schema for a module. +
+ + + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewGraphQLSchemaAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewGraphQLSchemaAction.java new file mode 100644 index 000000000..65b37bba8 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewGraphQLSchemaAction.java @@ -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; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/GraphQLSchema.java b/src/com/magento/idea/magento2plugin/magento/files/GraphQLSchema.java deleted file mode 100644 index 8a15c7ec2..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/GraphQLSchema.java +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -package com.magento.idea.magento2plugin.magento.files; - -public class GraphQLSchema { - public static String FILE_NAME = "schema.graphqls"; -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/SchemaGraphQLsFile.java b/src/com/magento/idea/magento2plugin/magento/files/SchemaGraphQLsFile.java new file mode 100644 index 000000000..7f929566b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/SchemaGraphQLsFile.java @@ -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; + } +} diff --git a/tests/com/magento/idea/magento2plugin/inspections/graphqls/SchemaResolverInspectionTest.java b/tests/com/magento/idea/magento2plugin/inspections/graphqls/SchemaResolverInspectionTest.java index 19610c8b0..a73a008ed 100644 --- a/tests/com/magento/idea/magento2plugin/inspections/graphqls/SchemaResolverInspectionTest.java +++ b/tests/com/magento/idea/magento2plugin/inspections/graphqls/SchemaResolverInspectionTest.java @@ -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 { @@ -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); }