JetBrains / js-graphql-intellij-plugin

GraphQL language support for WebStorm, IntelliJ IDEA and other IDEs based on the IntelliJ Platform.
https://jimkyndemeyer.github.io/js-graphql-intellij-plugin/
MIT License
879 stars 97 forks source link

Exception: com.intellij.lang.jsgraphql.types.AssertException: queryType expected #537

Closed piotrd closed 2 years ago

piotrd commented 2 years ago

Description

If the info below is not enough, please let me know.

Stacktrace

Please paste the full stacktrace from the IDEA error popup.

com.intellij.lang.jsgraphql.types.AssertException: queryType expected
    at com.intellij.lang.jsgraphql.types.Assert.assertNotNull(Assert.java:34)
    at com.intellij.lang.jsgraphql.ide.introspection.GraphQLIntrospectionResultToSchema.createSchemaDefinition(GraphQLIntrospectionResultToSchema.java:44)
    at com.intellij.lang.jsgraphql.ide.introspection.GraphQLIntrospectionService.printIntrospectionAsGraphQL(GraphQLIntrospectionService.java:328)
    at com.intellij.lang.jsgraphql.ide.introspection.GraphQLIntrospectionService.printIntrospectionAsGraphQL(GraphQLIntrospectionService.java:305)
    at com.intellij.lang.jsgraphql.ide.introspection.GraphQLIntrospectionFilesManager.lambda$getOrCreateIntrospectionSDL$0(GraphQLIntrospectionFilesManager.java:32)
    at com.intellij.psi.util.CachedValuesManager$1.compute(CachedValuesManager.java:158)
    at com.intellij.psi.impl.PsiCachedValueImpl.doCompute(PsiCachedValueImpl.java:39)
    at com.intellij.util.CachedValueBase.lambda$getValueWithLock$3(CachedValueBase.java:227)
    at com.intellij.util.CachedValueBase.computeData(CachedValueBase.java:42)
    at com.intellij.util.CachedValueBase.lambda$getValueWithLock$4(CachedValueBase.java:227)
    at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:114)
    at com.intellij.openapi.util.RecursionGuard.doPreventingRecursion(RecursionGuard.java:44)
    at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:68)
    at com.intellij.util.CachedValueBase.getValueWithLock(CachedValueBase.java:228)
    at com.intellij.psi.impl.PsiCachedValueImpl.getValue(PsiCachedValueImpl.java:28)
    at com.intellij.util.CachedValuesManagerImpl.getCachedValue(CachedValuesManagerImpl.java:72)
    at com.intellij.psi.util.CachedValuesManager.getCachedValue(CachedValuesManager.java:155)
    at com.intellij.lang.jsgraphql.ide.introspection.GraphQLIntrospectionFilesManager.getOrCreateIntrospectionSDL(GraphQLIntrospectionFilesManager.java:27)
    at com.intellij.lang.jsgraphql.ide.search.GraphQLPsiSearchHelper$4.visitElement(GraphQLPsiSearchHelper.java:271)
    at com.intellij.psi.impl.PsiElementBase.accept(PsiElementBase.java:273)
    at com.intellij.json.psi.impl.JsonLiteralImpl.accept(JsonLiteralImpl.java:26)
    at com.intellij.json.psi.impl.JsonStringLiteralImpl.accept(JsonStringLiteralImpl.java:28)
    at com.intellij.psi.impl.PsiElementBase.acceptChildren(PsiElementBase.java:69)
    at com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java:41)
    at com.intellij.lang.jsgraphql.ide.search.GraphQLPsiSearchHelper$4.visitElement(GraphQLPsiSearchHelper.java:282)
    at com.intellij.psi.impl.PsiElementBase.accept(PsiElementBase.java:273)
    at com.intellij.json.psi.impl.JsonPropertyImpl.accept(JsonPropertyImpl.java:27)
    at com.intellij.psi.impl.PsiElementBase.acceptChildren(PsiElementBase.java:69)
    at com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java:41)
    at com.intellij.lang.jsgraphql.ide.search.GraphQLPsiSearchHelper$4.visitElement(GraphQLPsiSearchHelper.java:282)
    at com.intellij.psi.impl.PsiElementBase.accept(PsiElementBase.java:273)
    at com.intellij.json.psi.impl.JsonValueImpl.accept(JsonValueImpl.java:26)
    at com.intellij.json.psi.impl.JsonContainerImpl.accept(JsonContainerImpl.java:27)
    at com.intellij.json.psi.impl.JsonObjectImpl.accept(JsonObjectImpl.java:27)
    at com.intellij.psi.impl.source.tree.SharedImplUtil.acceptChildren(SharedImplUtil.java:185)
    at com.intellij.psi.impl.source.PsiFileImpl.acceptChildren(PsiFileImpl.java:754)
    at com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java:41)
    at com.intellij.lang.jsgraphql.ide.search.GraphQLPsiSearchHelper$4.visitElement(GraphQLPsiSearchHelper.java:282)
    at com.intellij.psi.PsiElementVisitor.visitFile(PsiElementVisitor.java:35)
    at com.intellij.psi.PsiRecursiveElementVisitor.visitFile(PsiRecursiveElementVisitor.java:60)
    at com.intellij.extapi.psi.PsiFileBase.accept(PsiFileBase.java:60)
    at com.intellij.lang.jsgraphql.ide.search.GraphQLPsiSearchHelper.lambda$processElementsWithWordUsingIdentifierIndex$3(GraphQLPsiSearchHelper.java:286)
    at com.intellij.util.indexing.FileBasedIndexEx.processVirtualFiles(FileBasedIndexEx.java:522)
    at com.intellij.util.indexing.FileBasedIndexEx.processFilesContainingAllKeys(FileBasedIndexEx.java:362)
    at com.intellij.util.indexing.FileBasedIndexEx.getFilesWithKey(FileBasedIndexEx.java:433)
    at com.intellij.lang.jsgraphql.ide.search.GraphQLPsiSearchHelper.processElementsWithWordUsingIdentifierIndex(GraphQLPsiSearchHelper.java:249)
    at com.intellij.lang.jsgraphql.ide.search.GraphQLPsiSearchHelper.processElementsWithWord(GraphQLPsiSearchHelper.java:301)
    at com.intellij.lang.jsgraphql.ide.resolve.GraphQLReferenceService.resolveUsingIndex(GraphQLReferenceService.java:443)
    at com.intellij.lang.jsgraphql.ide.resolve.GraphQLReferenceService.resolveTypeName(GraphQLReferenceService.java:330)
    at com.intellij.lang.jsgraphql.ide.resolve.GraphQLReferenceService...

Version and Environment Details

Operation system: macOS 10.15.7 IDE version: WS-213.5744.224 Plugin version: 3.1.0

vepanimas commented 2 years ago

Hi @piotrd! Do you have any GraphQL schema in JSON format in your project? It could be any json file with similar structure:

{
    "__schema": {
        ...
    }
}

or

{
    "data": {
        "__schema": {
            ... 
        }
    }
}
vepanimas commented 2 years ago

Fixed in 3.1.2. Will be available as soon as the plugin will be approved in the marketplace.

piotrd commented 2 years ago

Hi @vepanimas. Sorry for the delay. I don't have a schema in JSON format. However, your fix seems to be working fine, so thank you!

vepanimas commented 2 years ago

@piotrd still could you please do a quick text search in the project for __schema string, maybe you have a regular JSON file that contains it, but it's not a GraphQL schema. Otherwise, I can't imagine how you've got this exception because it should fail several lines before with that assertion assertTrue(introspectionResult.get("__schema") != null, () -> "__schema expected"); 😕.

piotrd commented 2 years ago

Indeed there was such a JSON file with schema, although I wasn't aware of its existence.