Skip to content
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

"Unknown field" - does not resolve to a valid schema type (New in plugin version 2.5) #348

Closed
friederikewild opened this issue Jun 17, 2020 · 19 comments
Labels

Comments

@friederikewild
Copy link

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

  • Couldn't find any open issue that sounded like mine, but Wrong line separators error #347 also mentions something broken in 2.5 and working on 2.4 - not sure if related?
@jimkyndemeyer
Copy link
Collaborator

Hi Frederike,

Thanks for using the plugin.

Could you please attach a 2.5.0 screenshot of the GraphQL tool panel which shows the result of schema discovery and any errors that may prevent the schema from being built.

@AllanWang
Copy link

image

is that what you are looking for? I'm having the same issue. This is using the github schema (https://github.com/octokit/graphql-schema/blob/master/schema.json)

@jimkyndemeyer
Copy link
Collaborator

@AllanWang Thanks, yes it was. I see that the schema has been discovered, at least in your case.

On that basis I'm thinking that this may be related to indexing/caching used by the editor. Can you try the "File" > "Invalidate Caches / Restart" menu action and then click the "Invalidate and Restart" button?

@ErikRtvl
Copy link

ErikRtvl commented Jul 1, 2020

I am also having this issue. For me, the schema discovery looks OK (there are types, inputs and scalars).

Interesting remark is that it does find the types, and if I hover my mouse over the base query I get references to the schema.graphql file, but the fields are not recognized.

Even more funny thing is; it works fine in one project, but not in another project..... Both versions use the same version of graphql-tag. I tried the "Invalidate Caches" solution, but it didn't work.

@ErikRtvl
Copy link

ErikRtvl commented Jul 1, 2020

Just comparing both projects again. I work with python/graphene to build the server-side schema.

Initially, I named by query class "Query" and the mutation class "Mutation". In the old project where GraphQL JS worked well, I named them "ReadingQuery" and "MutationQuery".

class Query(graphene.ObjectType):
    ...

class Mutation(graphene.ObjectType):
    ....

schema = graphene.Schema(query=Query, mutation=Mutation)

So I renamed them in my current project as well, and now discovery works again!

class ReadingQuery(graphene.ObjectType):
    ...

class MutationQuery(graphene.ObjectType):
    ....

schema = graphene.Schema(query=ReadingQuery, mutation=MutationQuery)

Bit more testing shows that the root query in "schema.graphql" should not be named "Query". I named it "ReadingQuery" and all works fine. The name of the Mutation root type does not affect field discovery.

@blacksmoke26
Copy link

image
Same issue here.

PhpStorm 2020.2 EAP
Build #PS-202.6109.32, built on July 3, 2020
PhpStorm EAP User
Expiration date: August 2, 2020
Runtime version: 11.0.7+10-b944.16 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 8.1 6.3
---
JS GraphQL: v2.5.0

@simon2k
Copy link

simon2k commented Jul 15, 2020

Using the plugin with 2.4.0 version works fine, 2.5.0 cannot resolve the fields. I tried to invalidate cache but it does not help in this case, the same goes with using earlier versions of WebStorm.

WebStorm 2020.2 Beta
Build #WS-202.6250.10, built on July 8, 2020
WebStorm EAP User
Expiration date: August 7, 2020
Runtime version: 11.0.7+10-b944.18 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 4.19.0-9-amd64
GC: ParNew, ConcurrentMarkSweep
Memory: 725M
Cores: 8
Registry: ide.settings.move.mouse.on.default.button=true
Non-Bundled Plugins: com.intellij.lang.jsgraphql
Current Desktop: KDE

@jimkyndemeyer
Copy link
Collaborator

I'm still unable to reproduce this locally. It would be really helpful with specific steps to reproduce, or an example project that demonstrates the issue so that a fix is made possible.

@friederikewild
Copy link
Author

@jimkyndemeyer Sorry for not getting back earlier. Missed the notifications.
I just had a look at our production API schema.json and following the comment from @ErikRtvl I think these first few lines might be the issue when using the latest plugin version? I have no way of changing these & only have one big production project, but hope this might help:

{
  "__schema": {
    "queryType": {
      "name": "Query"
    },
    "mutationType": {
      "name": "Mutation"
    },
    "subscriptionType": {
      "name": "Subscription"
    },
    "types": [
      {
        "kind": "OBJECT",
        "name": "Query",
        "description": "",
        "fields": [
          {

@vepanimas vepanimas added the bug label Aug 19, 2020
@vepanimas vepanimas added this to the 2.6.0 milestone Aug 19, 2020
@vepanimas
Copy link
Collaborator

vepanimas commented Aug 26, 2020

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.

@vepanimas
Copy link
Collaborator

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

@segfaultDelirium
Copy link

segfaultDelirium commented Mar 14, 2022

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.

@nhlinh123
Copy link

same issue on 4.2.0 :(

@decorsstudio
Copy link

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)

@Dev-Addict
Copy link

I didn't have any issues using IntelliIdea on Windows but I started facing problems with the GraphQL plugin after using it on Linux. There might be a problem with the file system handling of IntellijIdea.

@ContrerasA
Copy link

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

@RemyMachado
Copy link

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

@cenekSvoboda
Copy link

I had a problem with unknown everything. Graphql config file may be in a wrong directory, try to put it into directory, where the schema actually is. In some setups it's one directory higher.

@CatalinGheorghiu
Copy link

CatalinGheorghiu commented Feb 25, 2024

I am using Graphql with Code Generator and graphql-request. I had the same issue.

image

What worked for me:

  1. Generated a graphql config via the graphql plugin. The file needs to be saved where the graphql.schema.json is.

Screenshot from 2024-02-25 14-41-37
image

  1. This generated a graphql.config.yml file which looked like this and pointed to the wrong file:

image

  1. I have then modified where the schema was pointing to:

image

My query now has autocomplete and the IDE is not complaining anymore.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests