js-graphql-intellij-plugin: "Unknown field" - does not resolve to a valid schema type (New in plugin version 2.5)

Describe the bug

  • Started to notice after update of the js-graphql plugin to version 2.5 (and Android studio to 4.0)
  • Viewing our file with grapql queries now all requested fields are red and on hovering show error “Unknown field”
  • No auto-suggestion when typing
  • But: Can still run queries against our Graphql endpoint
  • When installing the previous plugin version 2.4: All works fine with auto-suggestion and no red errors

To Reproduce

  • Sorry I’m only having a full production API graqhql, but here is the condensed definition related to the screenshots - maybe something to do with the extra defined type?
allStudios(
   first: Int
): StudioConnection!

type StudioConnection {
  edges: [StudioEdge!]
  pageInfo: PageInfo!
  totalCount: Int!
}

I really hope this helps. If not I can try to workout a simple demo project, but will take me longer

Expected behavior

  • No errors shown in graphql file
  • When typing after a query: get suggestions for the available fields

Screenshots

Using version 2.5:

Screenshot 2020-06-17 at 15 48 42

Screenshot 2020-06-17 at 15 51 06

Using version 2.4:

Screenshot 2020-06-17 at 15 53 14

Version and Environment Details Operation system: macOS IDE name and version: Android Studio 4.0 Plugin version: 2.5

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 18

Most upvoted comments

For anyone having trouble with this, I found out what I was doing wrong (This is in Webstorm, but should work the same in Intellij)

Create your .graphql.config file and click the green arrow icon to generate the schema.graphql image

This will create a new schema file in the chosen directory. You should then have auto complete and proper syntax highlighting in your own .graphql files image

Hello, I am currently having this problem. here is content of scratch.graphql file:

query ScratchQuery {
    allUsers{
      username
    }
}

When I run this query it correctly returns data, but when I hover over allUsers or username I get “Unknown field allUsers The parent selection or operation does not resolve to a valid schema type”.

How do I fix this and get schema autocompletion and validation?

I am using GraphQL 3.1.2 plugin in PycharmProfessional. Here is .graphqlconfig file content:

{
  "name": "Untitled GraphQL Schema",
  "schemaPath": "schema.graphql",
  "includes" : ["./src/**/*.graphql"],
  "extensions": {
    "endpoints": {
      "Default GraphQL Endpoint": {
        "url": "http://localhost:7777/graphql/",
        "headers": {
          "user-agent": "JS GraphQL"
        },
        "introspect": true
      }
    }
  }
}

the scratch.graphql file in in src folder. If you need more info please let me know.

I also get a A schema should have a 'query' operation defined error in my graphql window, but the generated by graphql schema has type Query defined, so I don’t know what the problem is.

I have also same issue image

WebStorm 2022.1.3 Build #WS-221.5921.27, built on June 22, 2022 Licensed to pawan Rana Subscription is active until August 15, 2022. Evaluation purpose only. Runtime version: 11.0.15+10-b2043.56 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 16 Registry: ide.balloon.shadow.size=0

Non-Bundled Plugins: ski.chrzanow.foldableprojectview (1.1.2) monokai-pro (1.8.1) mobi.hsz.idea.gitignore (4.4.0) izhangzhihao.rainbow.brackets (6.25) com.intellij.lang.jsgraphql (3.2.0) com.chrisrm.idea.MaterialThemeUI (7.5.4) com.mallowigi (64.0.0)

Closing due to lack of response. If the issue still exists in a new 2.6.0 version, please, feel free to comment here.

I was having error types since version upgrade. If this thread didn’t help, this #438 might help you getting things fixed.

I’m trying to reproduce this and I have a few guesses, but I’m not sure exactly what the reason is in each case. It would be ideal to get a complete schema, or at least a minimal set of types from it, for which it is possible to reproduce this bug + .graphqlconfig files.

  1. This may occur when something like graphql-modules lib is used, where repeated type declarations with the same name occur in the schema of various modules, which is valid from the library point of view (because these declarations are merged in runtime later), but is not supported in the plugin at the moment.

  2. Another possible reason is this pr in graphql-java 15. Now the schema will be broken if any type extensions with the same fields are found. Like

interface Human {
    id: ID!
    name: String!
}
extend interface Human {
    name: String! # the same field re-declared
    friends: [String]
}

Most of all, I want to understand at this point what the structure of your projects is. Specifically, are there places other than the schema specified in .graphqlconfig where types are defined?

Please, especially check if there are any Query type re-declarations type Query { or type extensions with extends keyword.

@friederikewild also errors from the schema file can also be very useful. I can see that you’re using schema.json file, but you can try using introspection to generate a file with a .graphql extension. It is quite possible that some errors will be visible in it.

@friederikewild @simon2k @blacksmoke26 @ErikRtvl any info from you is very appreciated 🙏! It looks like this issue is critical and common, but there are plenty of possible reasons for this behavior.