Fix Kotlin @DgsData fetchers never indexed due to PsiAnnotation cast#121
Open
MappuniMaku wants to merge 1 commit into
Open
Fix Kotlin @DgsData fetchers never indexed due to PsiAnnotation cast#121MappuniMaku wants to merge 1 commit into
MappuniMaku wants to merge 1 commit into
Conversation
For Kotlin annotations, sourcePsi is KtAnnotationEntry, not PsiAnnotation. The cast in processDataFetcher always returned null, so the component index was empty for every Kotlin data fetcher. Add UAnnotation overloads to DgsDataFetcher and thread UAnnotation through createDataFetchersForAnnotation so annotation metadata is read via UAST, which works for both languages.
|
Confirming this affects our Kotlin DGS project. Gutter icons have been grayed out for a couple of months. That's consistent with the December 2025 regression you identified. Navigation from schema to data fetchers is completely non-functional. Looking forward to this being merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey guys. It's now been a while since data fetchers navigation stopped working for my colleagues and me, so I decided to try to find and fix the issue using AI. I'm not specializing in Java/Kotlin development.
I tested it for the following IDEA versions:
./gradlew runIdegradle.properties, upgradingorg.jetbrains.kotlin.jvmto2.3.20and running./gradlew runIdegradle.properties, upgradingorg.jetbrains.kotlin.jvmto2.3.20and running./gradlew runIdeBelow is the AI summary of the bug that I asked it to write:
Issue
Gutter icons in Kotlin DGS projects appear as gray / unresolved ("no fetcher found"
variant). Clicking them does nothing — navigation to the GraphQL schema field is
completely broken. Java DGS projects are unaffected throughout.
Related issues: #83, #88, #102.
Root cause
In
DgsDataProcessor.kt, theprocessDataFetchermethod had:PsiAnnotationis a Java PSI interface. Java source annotations implement itdirectly. Kotlin source annotations use
KtAnnotationEntry, which does notimplement
PsiAnnotation. The cast therefore always returnednullfor Kotlin,createDataFetchersForAnnotationwas never called, and no Kotlin data fetcherwas ever added to the component index.
The bug was introduced in commit
2a4abb6("Properly handle implicit DgsData.Listlinkage", 2025-12-18), which refactored
processDataFetcherto separate the@DgsData.Listcontainer case but accidentally added the cast to theelsebranch.The original Kotlin compatibility commit from 2021 had used
uAnnotation.sourcePsidirectly without casting.
It went undetected because all existing test data files are Java; the Kotlin code
path was never exercised by tests.
Fix
DgsDataProcessor.kt— in theelsebranch, replace theas? PsiAnnotationcast with
uAnnotation.sourcePsi ?: returnand pass theUAnnotationdirectly tocreateDataFetchersForAnnotation. The method signature changes fromannotation: PsiAnnotationtouAnnotation: UAnnotation+annotationSourcePsi: PsiElement,so annotation attributes are read via UAST (works for both languages) while the
source PSI element is stored as-is for navigation.
In the
@DgsData.Listbranch, each extracted childPsiAnnotationis now convertedto
UAnnotationviatoUElement()before being passed to the same method, keepinga single code path for the indexing logic.
DgsDataFetcher.kt— addUAnnotationoverloads forgetParentTypeandgetFieldFromAnnotationas the primary implementations; make the existingPsiAnnotationoverloads delegate through them. This also removes an unsafe bareas UAnnotationcast that was already present in the original code.Tests
No test changes. The existing
DgsDataMultipleAnnotationsTestcovers both theimplicit
@Repeatableand explicit@DgsData.Listcases with Java test data andwas already asserting correct fetcher counts,
parentType/fieldvalues, schemalinkage, shared method references, and distinct annotation PSI elements per entry.
All tests pass.
Verified working
Manually tested via
./gradlew runIdeon:Gutter icons appear next to
@DgsQuery/@DgsMutation/@DgsDatamethods inKotlin DGS projects and navigate correctly to the GraphQL schema field.