Skip to content

[IJ Plugin] Don't report redefinitions of built-in types as errors #5131

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
merged 1 commit into from
Jul 27, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.apollographql.ijplugin.graphql

import com.intellij.lang.jsgraphql.ide.validation.GraphQLErrorFilter
import com.intellij.lang.jsgraphql.types.GraphQLError
import com.intellij.lang.jsgraphql.types.language.DirectiveDefinition
import com.intellij.lang.jsgraphql.types.language.EnumTypeDefinition
import com.intellij.lang.jsgraphql.types.language.ObjectTypeDefinition
import com.intellij.lang.jsgraphql.types.language.ScalarTypeDefinition
import com.intellij.lang.jsgraphql.types.schema.idl.errors.DirectiveRedefinitionError
import com.intellij.lang.jsgraphql.types.schema.idl.errors.TypeRedefinitionError
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement

/**
* Suppress redefinition errors for built-in GraphQL types/directives.
*
* TODO: remove this once https://github.com/JetBrains/js-graphql-intellij-plugin/issues/665 is fixed
*/
class BuiltInRedefinitionErrorFilter : GraphQLErrorFilter {
private val builtInScalarTypes = listOf("Int", "Float", "String", "Boolean", "ID")
private val builtInDirectives = listOf("skip", "include", "deprecated", "defer", "specifiedBy")

override fun isGraphQLErrorSuppressed(project: Project, error: GraphQLError, element: PsiElement?): Boolean {
return when (error) {
is TypeRedefinitionError -> {
when (val node = error.node) {
is ScalarTypeDefinition -> {
node.name in builtInScalarTypes
}

is ObjectTypeDefinition -> {
node.name.startsWith("__")
}

is EnumTypeDefinition -> {
node.name.startsWith("__")
}

else -> false
}
}

is DirectiveRedefinitionError -> {
(error.node as DirectiveDefinition).name in builtInDirectives
}

else -> false
}
}
}
6 changes: 5 additions & 1 deletion intellij-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@

</extensions>

<!-- Contribute configuration to the GraphQL plugin -->
<extensions defaultExtensionNs="com.intellij.lang.jsgraphql">
<!-- Contribute configuration to the GraphQL plugin -->
<configContributor implementation="com.apollographql.ijplugin.graphql.ApolloGraphQLConfigContributor" />

<!-- Suppress redefinition errors for built-in GraphQL types/directives. -->
<!-- TODO: remove this once https://github.com/JetBrains/js-graphql-intellij-plugin/issues/665 is fixed -->
<errorFilter implementation="com.apollographql.ijplugin.graphql.BuiltInRedefinitionErrorFilter" />
</extensions>

<applicationListeners>
Expand Down