Skip to content

Commit 2cbb68b

Browse files
committed
Allow keywords to be used for as field names (#239) (#264)
- Upgraded graphql-java to 14.0 (graphql-java/graphql-java#1523) - Refactored breaking changes from graphql-java 12.0 to 14.0
1 parent 6754682 commit 2cbb68b

File tree

15 files changed

+54
-34
lines changed

15 files changed

+54
-34
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repositories {
1717
}
1818

1919
dependencies {
20-
compile ("com.graphql-java:graphql-java:12.0") {
20+
compile ("com.graphql-java:graphql-java:14.0") {
2121
exclude group: "org.reactivestreams", module: "reactive-streams"
2222
exclude group: "com.graphql-java", module: "java-dataloader"
2323
exclude group: "org.slf4j", module: "slf4j-api"

gen/com/intellij/lang/jsgraphql/GraphQLParser.java

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grammars/GraphQLParser.bnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ argument ::= identifier ':' value {pin=1 methods=[nameIdentifier="identifier"] r
123123

124124
private argument_recover ::= !(')' | argument)
125125

126-
identifier ::= NAME | 'fragment' | 'query' | 'mutation' | 'subscription' | 'schema' | 'scalar' | 'type' | 'interface' | 'implements' | 'enum' | 'union' | 'input' | 'extend' | 'directive' {mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLReferencePsiElement"}
126+
identifier ::= NAME | 'fragment' | 'query' | 'mutation' | 'subscription' | 'schema' | 'scalar' | 'type' | 'interface' | 'implements' | 'enum' | 'union' | 'input' | 'extend' | 'directive' | 'on' {mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLReferencePsiElement"}
127127

128128
private templatePlaceholder ::= DOLLAR BRACE_L TEMPLATE_CHAR* BRACE_R
129129

src/main/com/intellij/lang/jsgraphql/ide/GraphQLValidationAnnotator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder a
107107
} else if (typeScope instanceof GraphQLInterfaceType) {
108108
definitionType = "interface ";
109109
}
110-
message += " on " + definitionType + "type \"" + typeScope.getName() + "\"";
110+
message += " on " + definitionType + "type \"" + GraphQLUtil.getName(typeScope) + "\"";
111111
final List<String> suggestions = getFieldNameSuggestions(psiElement.getText(), typeScope);
112112
if (suggestions != null && !suggestions.isEmpty()) {
113113
message += ". Did you mean " + formatSuggestions(suggestions) + "?";
@@ -133,7 +133,7 @@ public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder a
133133
} else if (parent instanceof GraphQLObjectField) {
134134
message = "Unknown field \"" + psiElement.getText() + "\"";
135135
if (typeScope != null) {
136-
message += " on input type \"" + typeScope.getName() + "\"";
136+
message += " on input type \"" + GraphQLUtil.getName(typeScope) + "\"";
137137
final List<String> suggestions = getFieldNameSuggestions(psiElement.getText(), typeScope);
138138
if (suggestions != null && !suggestions.isEmpty()) {
139139
message += ". Did you mean " + formatSuggestions(suggestions) + "?";

src/main/com/intellij/lang/jsgraphql/ide/completion/GraphQLCompletionContributor.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.intellij.lang.jsgraphql.psi.GraphQLEnumValueDefinition;
2323
import com.intellij.lang.jsgraphql.psi.GraphQLFieldDefinition;
2424
import com.intellij.lang.jsgraphql.psi.*;
25+
import com.intellij.lang.jsgraphql.psi.GraphQLInputValueDefinition;
2526
import com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware;
2627
import com.intellij.lang.jsgraphql.psi.impl.GraphQLObjectValueImpl;
2728
import com.intellij.lang.jsgraphql.schema.GraphQLTypeDefinitionRegistryServiceImpl;
@@ -376,7 +377,7 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
376377
final GraphQLUnmodifiedType rawType = GraphQLUtil.getUnmodifiedType(typeScope);
377378
if (rawType instanceof GraphQLEnumType) {
378379
((GraphQLEnumType) rawType).getValues().forEach(value -> {
379-
result.addElement(LookupElementBuilder.create(value.getName()).withTypeText(typeScope.getName()));
380+
result.addElement(LookupElementBuilder.create(value.getName()).withTypeText(GraphQLUtil.getName(typeScope)));
380381
});
381382
} else if (rawType instanceof GraphQLInputObjectType) {
382383
if (parameters.getOriginalPosition() != null && !parameters.getOriginalPosition().getText().equals("{")) {
@@ -412,7 +413,7 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
412413
final GraphQLUnmodifiedType rawType = GraphQLUtil.getUnmodifiedType(typeScope);
413414
if (rawType instanceof GraphQLEnumType) {
414415
((GraphQLEnumType) rawType).getValues().forEach(value -> {
415-
result.addElement(LookupElementBuilder.create(value.getName()).withTypeText(typeScope.getName()));
416+
result.addElement(LookupElementBuilder.create(value.getName()).withTypeText(rawType.getName()));
416417
});
417418
}
418419
}
@@ -744,9 +745,9 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
744745
typeScopeProvider = PsiTreeUtil.getParentOfType(typeScopeProvider, GraphQLTypeScopeProvider.class);
745746
}
746747

747-
GraphQLType typeScope = typeScopeProvider != null ? typeScopeProvider.getTypeScope() : null;
748-
if (typeScope != null) {
749-
typeScope = GraphQLUtil.getUnmodifiedType(typeScope); // unwrap non-null and lists since fragments are about the raw type
748+
GraphQLType rawTypeScope = typeScopeProvider != null ? typeScopeProvider.getTypeScope() : null;
749+
if (rawTypeScope != null) {
750+
GraphQLUnmodifiedType typeScope = GraphQLUtil.getUnmodifiedType(rawTypeScope); // unwrap non-null and lists since fragments are about the raw type
750751
final TypeDefinition fragmentType = typeDefinitionRegistry.getType(typeScope.getName()).orElse(null);
751752
if (fragmentType != null) {
752753
final Ref<Consumer<TypeDefinition<?>>> addTypesRecursive = new Ref<>();
@@ -1133,7 +1134,7 @@ private boolean isFragmentApplicableInTypeScope(TypeDefinitionRegistry typeDefin
11331134
}
11341135

11351136
final String fragmentTypeName = Optional.ofNullable(typeCondition.getTypeName().getName()).orElse("");
1136-
if (fragmentTypeName.equals(requiredTypeScope.getName())) {
1137+
if (fragmentTypeName.equals(GraphQLUtil.getName(requiredTypeScope))) {
11371138
// direct match, e.g. User scope, fragment on User
11381139
return true;
11391140
}
@@ -1147,14 +1148,14 @@ private boolean isFragmentApplicableInTypeScope(TypeDefinitionRegistry typeDefin
11471148
* Gets whether a fragment type condition name is compatible with the required type scope
11481149
*
11491150
* @param typeDefinitionRegistry registry with available schema types, used to resolve union members and interface implementations
1150-
* @param requiredTypeScope the type scope in which the fragment is a candidate to spread
1151+
* @param rawRequiredTypeScope the type scope in which the fragment is a candidate to spread
11511152
* @param fragmentTypeName the name of the type that a candidate fragment applies to
11521153
* @return true if the candidate type condtion name is compatible inside the required type scope
11531154
*/
1154-
private boolean isCompatibleFragment(TypeDefinitionRegistry typeDefinitionRegistry, GraphQLType requiredTypeScope, String fragmentTypeName) {
1155+
private boolean isCompatibleFragment(TypeDefinitionRegistry typeDefinitionRegistry, GraphQLType rawRequiredTypeScope, String fragmentTypeName) {
11551156

11561157
// unwrap non-nullable and list types
1157-
requiredTypeScope = GraphQLUtil.getUnmodifiedType(requiredTypeScope);
1158+
GraphQLUnmodifiedType requiredTypeScope = GraphQLUtil.getUnmodifiedType(rawRequiredTypeScope);
11581159

11591160
if (requiredTypeScope instanceof GraphQLInterfaceType) {
11601161
// also include fragments on types implementing the interface scope
@@ -1169,13 +1170,13 @@ private boolean isCompatibleFragment(TypeDefinitionRegistry typeDefinitionRegist
11691170
}
11701171
} else if (requiredTypeScope instanceof GraphQLObjectType) {
11711172
// include fragments on the interfaces implemented by the object type
1172-
for (GraphQLOutputType graphQLOutputType : ((GraphQLObjectType) requiredTypeScope).getInterfaces()) {
1173+
for (GraphQLNamedOutputType graphQLOutputType : ((GraphQLObjectType) requiredTypeScope).getInterfaces()) {
11731174
if (graphQLOutputType.getName().equals(fragmentTypeName)) {
11741175
return true;
11751176
}
11761177
}
11771178
} else if (requiredTypeScope instanceof GraphQLUnionType) {
1178-
for (GraphQLOutputType graphQLOutputType : ((GraphQLUnionType) requiredTypeScope).getTypes()) {
1179+
for (GraphQLNamedOutputType graphQLOutputType : ((GraphQLUnionType) requiredTypeScope).getTypes()) {
11791180
// check each type in the union for compatibility
11801181
if (graphQLOutputType.getName().equals(fragmentTypeName) || isCompatibleFragment(typeDefinitionRegistry, graphQLOutputType, fragmentTypeName)) {
11811182
return true;

src/main/com/intellij/lang/jsgraphql/ide/documentation/GraphQLDocumentationProvider.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import com.intellij.lang.jsgraphql.endpoint.psi.JSGraphQLEndpointDocumentationAware;
1212
import com.intellij.lang.jsgraphql.endpoint.psi.JSGraphQLEndpointFile;
1313
import com.intellij.lang.jsgraphql.psi.GraphQLFieldDefinition;
14+
import com.intellij.lang.jsgraphql.psi.GraphQLInputValueDefinition;
1415
import com.intellij.lang.jsgraphql.psi.GraphQLType;
1516
import com.intellij.lang.jsgraphql.psi.*;
1617
import com.intellij.lang.jsgraphql.schema.GraphQLTypeDefinitionRegistryServiceImpl;
18+
import com.intellij.lang.jsgraphql.utils.GraphQLUtil;
1719
import com.intellij.psi.PsiElement;
1820
import com.intellij.psi.PsiManager;
1921
import com.intellij.psi.util.PsiTreeUtil;
@@ -213,8 +215,8 @@ private String getArgumentDocumentation(GraphQLSchema schema, GraphQLInputValueD
213215
if (inputValueName.equals(inputObjectField.getName())) {
214216
GraphQLInputType type = inputObjectField.getType();
215217
final StringBuilder result = new StringBuilder().append(DEFINITION_START);
216-
result.append(schemaType.getName()).append(".");
217-
result.append(inputValueName).append(type != null ? ": " : "").append(type != null ? type.getName() : "");
218+
result.append(GraphQLUtil.getName(schemaType)).append(".");
219+
result.append(inputValueName).append(type != null ? ": " : "").append(type != null ? GraphQLUtil.getName(type) : "");
218220
result.append(DEFINITION_END);
219221

220222
final String description = inputObjectField.getDescription();
@@ -233,7 +235,7 @@ private String getArgumentDocumentation(GraphQLSchema schema, GraphQLInputValueD
233235
private String getArgumentDocumentation(String inputValueName, GraphQLArgument argument) {
234236
final StringBuilder html = new StringBuilder().append(DEFINITION_START);
235237
GraphQLInputType argumentType = argument.getType();
236-
html.append(inputValueName).append(argumentType != null ? ": " : " ").append(argumentType != null ? argumentType.getName() : "");
238+
html.append(inputValueName).append(argumentType != null ? ": " : " ").append(argumentType != null ? GraphQLUtil.getName(argumentType) : "");
237239
html.append(DEFINITION_END);
238240
appendDescription(html, GraphQLDocumentationMarkdownRenderer.getDescriptionAsHTML(argument.getDescription()));
239241
return html.toString();
@@ -254,7 +256,7 @@ private String getFieldDocumentation(PsiElement element, GraphQLSchema schema, G
254256
if (schemaType != null) {
255257
final String fieldName = element.getText();
256258
final StringBuilder html = new StringBuilder().append(DEFINITION_START);
257-
html.append(schemaType.getName()).append(".");
259+
html.append(GraphQLUtil.getName(schemaType)).append(".");
258260
html.append(fieldName).append(psiFieldType != null ? ": " : "").append(psiFieldType != null ? psiFieldType.getText() : "");
259261
html.append(DEFINITION_END);
260262
List<graphql.schema.GraphQLFieldDefinition> fieldDefinitions = null;

src/main/com/intellij/lang/jsgraphql/ide/editor/GraphQLIntrospectionHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class GraphQLIntrospectionHelper {
7474
private GraphQLIntrospectionTask latestIntrospection = null;
7575
private Project myProject;
7676

77+
private static Set<String> DEFAULT_DIRECTIVES = Sets.newHashSet("deprecated", "skip", "include");
78+
7779
public static GraphQLIntrospectionHelper getService(@NotNull Project project) {
7880
return ServiceManager.getService(project, GraphQLIntrospectionHelper.class);
7981
}
@@ -271,7 +273,11 @@ public String printIntrospectionJsonAsGraphQL(String introspectionJson) {
271273
}
272274

273275
final Document schemaDefinition = new GraphQLIntrospectionResultToSchema().createSchemaDefinition(introspectionAsMap);
274-
final SchemaPrinter.Options options = SchemaPrinter.Options.defaultOptions().includeScalarTypes(false).includeSchemaDefintion(true);
276+
final SchemaPrinter.Options options = SchemaPrinter.Options
277+
.defaultOptions()
278+
.includeScalarTypes(false)
279+
.includeSchemaDefinition(true)
280+
.includeDirectives(directive -> !DEFAULT_DIRECTIVES.contains(directive.getName()));
275281
final TypeDefinitionRegistry registry = new SchemaParser().buildRegistry(schemaDefinition);
276282
final StringBuilder sb = new StringBuilder(new SchemaPrinter(options).print(buildIntrospectionSchema(registry)));
277283

src/main/com/intellij/lang/jsgraphql/ide/references/GraphQLReferenceService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,14 @@ public void visitElement(final PsiElement schemaElement) {
243243
final GraphQLTypeDefinition typeDefinition = PsiTreeUtil.getParentOfType(psiNamedElement, GraphQLTypeDefinition.class);
244244
if (typeDefinition != null) {
245245
final GraphQLTypeNameDefinition typeNameDefinition = PsiTreeUtil.findChildOfType(typeDefinition, GraphQLTypeNameDefinition.class);
246-
isTypeMatch = typeNameDefinition != null && fieldType.getName().equals(typeNameDefinition.getName());
246+
isTypeMatch = typeNameDefinition != null && GraphQLUtil.getName(fieldType).equals(typeNameDefinition.getName());
247247
}
248248
if (!isTypeMatch) {
249249
// check type extension
250250
final GraphQLTypeExtension typeExtension = PsiTreeUtil.getParentOfType(psiNamedElement, GraphQLTypeExtension.class);
251251
if (typeExtension != null) {
252252
final GraphQLTypeName typeName = PsiTreeUtil.findChildOfType(typeExtension, GraphQLTypeName.class);
253-
isTypeMatch = typeName != null && fieldType.getName().equals(typeName.getName());
253+
isTypeMatch = typeName != null && GraphQLUtil.getName(fieldType).equals(typeName.getName());
254254
}
255255
}
256256
if (isTypeMatch) {

src/main/com/intellij/lang/jsgraphql/schema/SchemaIDLTypeDefinitionRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void onGraphQLSchemaChanged(Integer schemaVersion) {
9191
STANDARD_SCALAR_DEFINITIONS.remove("BigDecimal");
9292
STANDARD_SCALAR_DEFINITIONS.remove("Short");
9393
STANDARD_SCALAR_DEFINITIONS.remove("Char");
94+
STANDARD_SCALAR_DEFINITIONS.remove("Byte");
9495

9596
}
9697

src/main/com/intellij/lang/jsgraphql/schema/SchemaIDLUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import graphql.schema.GraphQLList;
1111
import graphql.schema.GraphQLNonNull;
1212
import graphql.schema.GraphQLType;
13+
import graphql.schema.GraphQLUnmodifiedType;
1314

1415
import java.util.Stack;
1516

@@ -32,8 +33,11 @@ public static String typeString(GraphQLType rawType) {
3233
type = ((GraphQLList) type).getWrappedType();
3334
sb.append("[");
3435
stack.push("]");
36+
} else if (type instanceof GraphQLUnmodifiedType) {
37+
sb.append(((GraphQLUnmodifiedType) type).getName());
38+
break;
3539
} else {
36-
sb.append(type.getName());
40+
sb.append(type.toString());
3741
break;
3842
}
3943
}

0 commit comments

Comments
 (0)