js-graphql-intellij-plugin icon indicating copy to clipboard operation
js-graphql-intellij-plugin copied to clipboard

A schema should have a 'query' operation defined, but Query type is defined.

Open segfaultDelirium opened this issue 2 years ago • 3 comments

Hello, I am currently having a problem with GraphQL plugin for PyCharm. In GraphQL window in PyCharm I get a Schema error A schema should have a 'query' operation defined. Introspection works and the generated by the plugin schema has type Query defined! wtf?

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

{
  "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
      }
    }
  }
}

Expected behaviour is that the graphql plugin detects the Query type that it itself generated.

Screenshots a_schema_should_have_query

Version and Environment Details Operation system: Linux Mint 20.3 Cinnamon IDE name and version: PyCharm Professional 2021.3.2 Plugin version: 3.1.2

If you need more info please let me know. How do I solve this problem? Am I missing something?

segfaultDelirium avatar Mar 14 '22 18:03 segfaultDelirium

Where is the schema section of your graphql file (starting at line 1)? It should look like

schema {
  query: Query
  mutation: Mutation
  subscription: Subscription
}

or subscription: null if your API doesn't support notifications.

I'm just guessing, but the error sounds like it's complaining about a missing operation, not a missing type definition.

davaya avatar May 01 '22 01:05 davaya

@segfaultDelirium hey, sorry for the late response. It looks like the GraphQL file type wasn't recognized by the IDE for some reason, an opened file has the wrong icon in the tab header. I fixed an issue with file types in the past few releases, so it possibly could be fixed already. If it's still an issue please ping me.

@davaya it's not required to specify a schema explicitly if your operations have default names like Query, Mutation, and Subscription. The plugin should respect that naming convention and it's expected to work out of the box.

vepanimas avatar Jul 16 '22 00:07 vepanimas

@segfaultDelirium came across same issues, these two fixes solved it

  1. check if your "name" and "endpoints" match e.g.:
  "name": "SOME_NAME",  <---- need to match
  ....
  "extensions": {
    "endpoints": {
      "SOME_NAME": { <---- need to match
       .....
        },
      }
    }
  }
}
  1. simply delete generated schema.graphql file and generate it from scratch

Leeasc avatar Aug 15 '22 09:08 Leeasc