Skip to content

Commit a3d88bf

Browse files
authored
[IJ Plugin] Don't report redefinitions of built-in types as errors (#5131)
1 parent 6bc0691 commit a3d88bf

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.apollographql.ijplugin.graphql
2+
3+
import com.intellij.lang.jsgraphql.ide.validation.GraphQLErrorFilter
4+
import com.intellij.lang.jsgraphql.types.GraphQLError
5+
import com.intellij.lang.jsgraphql.types.language.DirectiveDefinition
6+
import com.intellij.lang.jsgraphql.types.language.EnumTypeDefinition
7+
import com.intellij.lang.jsgraphql.types.language.ObjectTypeDefinition
8+
import com.intellij.lang.jsgraphql.types.language.ScalarTypeDefinition
9+
import com.intellij.lang.jsgraphql.types.schema.idl.errors.DirectiveRedefinitionError
10+
import com.intellij.lang.jsgraphql.types.schema.idl.errors.TypeRedefinitionError
11+
import com.intellij.openapi.project.Project
12+
import com.intellij.psi.PsiElement
13+
14+
/**
15+
* Suppress redefinition errors for built-in GraphQL types/directives.
16+
*
17+
* TODO: remove this once https://github.com/JetBrains/js-graphql-intellij-plugin/issues/665 is fixed
18+
*/
19+
class BuiltInRedefinitionErrorFilter : GraphQLErrorFilter {
20+
private val builtInScalarTypes = listOf("Int", "Float", "String", "Boolean", "ID")
21+
private val builtInDirectives = listOf("skip", "include", "deprecated", "defer", "specifiedBy")
22+
23+
override fun isGraphQLErrorSuppressed(project: Project, error: GraphQLError, element: PsiElement?): Boolean {
24+
return when (error) {
25+
is TypeRedefinitionError -> {
26+
when (val node = error.node) {
27+
is ScalarTypeDefinition -> {
28+
node.name in builtInScalarTypes
29+
}
30+
31+
is ObjectTypeDefinition -> {
32+
node.name.startsWith("__")
33+
}
34+
35+
is EnumTypeDefinition -> {
36+
node.name.startsWith("__")
37+
}
38+
39+
else -> false
40+
}
41+
}
42+
43+
is DirectiveRedefinitionError -> {
44+
(error.node as DirectiveDefinition).name in builtInDirectives
45+
}
46+
47+
else -> false
48+
}
49+
}
50+
}

intellij-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,13 @@
133133

134134
</extensions>
135135

136-
<!-- Contribute configuration to the GraphQL plugin -->
137136
<extensions defaultExtensionNs="com.intellij.lang.jsgraphql">
137+
<!-- Contribute configuration to the GraphQL plugin -->
138138
<configContributor implementation="com.apollographql.ijplugin.graphql.ApolloGraphQLConfigContributor" />
139+
140+
<!-- Suppress redefinition errors for built-in GraphQL types/directives. -->
141+
<!-- TODO: remove this once https://github.com/JetBrains/js-graphql-intellij-plugin/issues/665 is fixed -->
142+
<errorFilter implementation="com.apollographql.ijplugin.graphql.BuiltInRedefinitionErrorFilter" />
139143
</extensions>
140144

141145
<applicationListeners>

0 commit comments

Comments
 (0)