Skip to content

Commit 512ceeb

Browse files
committed
Merge branch 'master' into Endpoint
# Conflicts: # resources/META-INF/plugin.xml
2 parents 8345ba7 + 6289c01 commit 512ceeb

File tree

6 files changed

+117
-1
lines changed

6 files changed

+117
-1
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 1.4.2 (2016-09-25)
2+
3+
Features:
4+
5+
- Language Service 1.3.1: Support __schema root in schema.json (compatible with graphene)
6+
7+
Changes:
8+
9+
- Fixes formatting exception when using ".if" live template in JSFile with injected GraphQL (#26)
10+
111
## 1.4.1 (2016-09-11)
212

313
Features:

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ To install it, open "Settings", "Plugins", "Browse repositories..." and search f
4242

4343
**Note**: The experimental version in the `android-studio` branch is not available from the JetBrains Plugin Repository.
4444

45+
**How do I configure the plugin in a project**
46+
47+
The plugin is activated as soon as you view or edit GraphQL in the editor. This includes GraphQL inside `Relay.QL` and `gql` templates in JavaScript and TypeScript. You can also use `.graphql` physical files and scratch files. These files allow you to query your endpoint directly from your IDE.
48+
49+
An editor notification bar should prompt you to "Create a graphql.config.json". Accept and edit this config file to point the plugin at your local `schema.json` or your endpoint for introspection. The plugin uses the schema to provide completion and error highlighting.
50+
4551
**How do I reload a GraphQL Schema that was loaded from a URL?**
4652

4753
In the the GraphQL tool window, select the "Current Errors" tab and click the "Restart JS GraphQL Language Service" button.

resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<change-notes><![CDATA[
3131
<ul>
32+
<li>1.4.2: Language Service 1.3.1: Support __schema root in schema.json.</li>
3233
<li>1.4.1: Support for gql tagged templates used by Apollo and Lokka GraphQL Clients. Fixes false Error in Relay Mutation.</li>
3334
<li>1.4.0: Language Service 1.2.0 based on graphql 0.7.0 and codemirror-graphql 0.5.4. Basic editor support for GraphQL Schema (.graphqls)</li>
3435
<li>1.3.3: Fixes compatibility issue with IDEA 2016.2.2</li>
@@ -131,6 +132,8 @@
131132
<lang.quoteHandler language="GraphQL Schema" implementationClass="com.intellij.lang.jsgraphql.ide.editor.JSGraphQLQuoteHandler" />
132133
<lang.quoteHandler language="GraphQL Endpoint" implementationClass="com.intellij.lang.jsgraphql.endpoint.ide.editor.JSGraphQLEndpointQuoteHandler" />
133134
<enterHandlerDelegate implementation="com.intellij.lang.jsgraphql.ide.formatter.JSGraphQLEnterHandlerDelegate" />
135+
<langCodeStyleSettingsProvider implementation="com.intellij.lang.jsgraphql.ide.formatter.JSGraphQLLanguageCodeStyleSettingsProvider"/>
136+
<codeStyleSettingsProvider implementation="com.intellij.lang.jsgraphql.ide.formatter.JSGraphQLCodeStyleSettingsProvider" />
134137

135138

136139
<!-- Find usages -->

src/main/com/intellij/lang/jsgraphql/ide/formatter/JSGraphQLCodeStyleSettingsProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,14 @@ private static class JSGraphQLCodeStyleMainPanel extends TabbedLanguageCodeStyle
5151
public JSGraphQLCodeStyleMainPanel(CodeStyleSettings currentSettings, CodeStyleSettings settings) {
5252
super(JSGraphQLLanguage.INSTANCE, currentSettings, settings);
5353
}
54+
55+
@Override
56+
protected void addSpacesTab(CodeStyleSettings settings) {}
57+
58+
@Override
59+
protected void addBlankLinesTab(CodeStyleSettings settings) {}
60+
61+
@Override
62+
protected void addWrappingAndBracesTab(CodeStyleSettings settings) {}
5463
}
5564
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Copyright (c) 2015-present, Jim Kynde Meyer
3+
* All rights reserved.
4+
* <p>
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
package com.intellij.lang.jsgraphql.ide.formatter;
9+
10+
import com.intellij.application.options.IndentOptionsEditor;
11+
import com.intellij.lang.Language;
12+
import com.intellij.lang.jsgraphql.JSGraphQLLanguage;
13+
import com.intellij.openapi.application.ApplicationBundle;
14+
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
15+
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
16+
import org.jetbrains.annotations.NotNull;
17+
import org.jetbrains.annotations.Nullable;
18+
19+
import javax.swing.*;
20+
21+
public class JSGraphQLLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider {
22+
23+
@NotNull
24+
@Override
25+
public Language getLanguage() {
26+
return JSGraphQLLanguage.INSTANCE;
27+
}
28+
29+
@Nullable
30+
@Override
31+
public CommonCodeStyleSettings getDefaultCommonSettings() {
32+
final CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(getLanguage());
33+
CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();
34+
indentOptions.INDENT_SIZE = 4;
35+
indentOptions.USE_TAB_CHARACTER = false;
36+
return defaultSettings;
37+
}
38+
39+
@Nullable
40+
@Override
41+
public IndentOptionsEditor getIndentOptionsEditor() {
42+
return new IndentOptionsEditor() {
43+
protected void addComponents() {
44+
addTabOptions();
45+
myTabSizeField = new JTextField();
46+
myTabSizeLabel = new JLabel();
47+
myIndentField = createIndentTextField();
48+
myIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.indent"));
49+
add(myIndentLabel, myIndentField);
50+
}
51+
52+
protected void addTabOptions() {
53+
myCbUseTab = new JCheckBox("");
54+
}
55+
};
56+
}
57+
58+
@Override
59+
public String getCodeSample(@NotNull SettingsType settingsType) {
60+
return "query MyQuery {\n" +
61+
" __schema {\n" +
62+
" types {\n" +
63+
" ...FullType\n" +
64+
" }\n" +
65+
" }\n" +
66+
"}\n" +
67+
"\n" +
68+
"fragment FullType on __Type {\n" +
69+
" # Note: __Type has a lot more fields than this\n" +
70+
" name\n" +
71+
"}\n" +
72+
"\n" +
73+
"mutation MyMutation($input: MyInput!) {\n" +
74+
" # Payload\n" +
75+
"}\n";
76+
}
77+
}

src/main/com/intellij/lang/jsgraphql/ide/highlighting/JSGraphQLSyntaxHighlighterFactory.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,28 @@
88
package com.intellij.lang.jsgraphql.ide.highlighting;
99

1010
import com.intellij.lang.jsgraphql.schema.JSGraphQLSchemaFileType;
11+
import com.intellij.openapi.fileTypes.PlainSyntaxHighlighter;
1112
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
1213
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
1314
import com.intellij.openapi.project.Project;
15+
import com.intellij.openapi.project.ProjectManager;
1416
import com.intellij.openapi.vfs.VirtualFile;
1517
import org.jetbrains.annotations.NotNull;
1618

1719
public class JSGraphQLSyntaxHighlighterFactory extends SyntaxHighlighterFactory {
1820
@NotNull
1921
@Override
2022
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
21-
final boolean schema = virtualFile.getFileType() == JSGraphQLSchemaFileType.INSTANCE;
23+
final boolean schema = virtualFile != null && virtualFile.getFileType() == JSGraphQLSchemaFileType.INSTANCE;
24+
if(project == null) {
25+
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
26+
if(openProjects.length > 0) {
27+
project = openProjects[0];
28+
} else {
29+
// can't syntax highlight GraphQL without a project to associate the language service instance to
30+
return new PlainSyntaxHighlighter();
31+
}
32+
}
2233
return new JSGraphQLSyntaxHighlighter(project, schema);
2334
}
2435
}

0 commit comments

Comments
 (0)