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

A schema MUST have a 'query' operation defined Error. But I have type Query in my schema.

Open tintin10q opened this issue 3 years ago • 14 comments

I have added my schema to a .graphql file in my main project directory. I now get this error: image

This is very weird because I do have a type Query {} in my .graphql file with multiple queries in there. When I copied the Query type into an empty .graphql file and I changed all the return types to strings I did not get the error anymore. To Reproduce I don't really know how you could reproduce this I don't want really share my schema.

Expected behavior I don't expect a 'A schema MUST have a 'query' operation defined' error to pop up when there is a type Query in the schema

Version and Environment Details Operation system: Win 10 IDE name and version: Webstorm 2020.3.2 Plugin version: 2.9.1

tintin10q avatar May 06 '21 17:05 tintin10q

Same here

binary64 avatar May 10 '21 11:05 binary64

Please could you bubble up the error message from parsing the file? At least if we know a line number of the .graphql that is causing the issue, I could open a better issue with a more exact feature request.

binary64 avatar May 24 '21 16:05 binary64

image

binary64 avatar May 24 '21 16:05 binary64

Sorry but I am not sure what you mean with bubble up the error message from parsing the file.

tintin10q avatar May 24 '21 16:05 tintin10q

I feel the graphql parser used from your plugin is not liking my schema.graphql (>100k lines). I've tried snipping off random bits in an attempt to narrow down what is causing the issue (for example enum's), but no luck so far. What I ideally need is to see the inner exception - something like "Unexpected token on line 178937".

It feels like the parse happened inside a try/catch block, and it silently failed, causing the schema to have no query (the error I see).

binary64 avatar May 24 '21 20:05 binary64

@binary64 I ran into the same error as well. Do you use a schema inside the node_modules folder?

davidenke avatar Jun 09 '21 10:06 davidenke

I struggled with the same error for a while. Then I accidentally deleted the project from IntelliJ and removed all hidden IDE subfolders, and when I re-added the same project folder back to WebStorm the plugin worked perfectly again. Worth a try :)

eugene1g avatar Jun 09 '21 15:06 eugene1g

Unfortunately, this is a common error that occurs when the schema could not be built for some reason. I've improved error handling and logging in the upcoming version that I'll release soon.

vepanimas avatar Jul 20 '21 19:07 vepanimas

@vepanimas

I experience this issue on Webstorm 2021.3.2 and plugin version 3.1.2, even with the simplest example of relay-schema.graphql and .graphqlconfig:

image

goktugerce avatar Feb 13 '22 21:02 goktugerce

@goktugerce Temporary solution is install plugin version 3.0.0 from https://plugins.jetbrains.com/plugin/8097-graphql/versions

Mozzarella123 avatar Mar 20 '22 09:03 Mozzarella123

@Mozzarella123 I tried, and it didn't help.

segfaultDelirium avatar Apr 03 '22 04:04 segfaultDelirium

Same Problem. Schema is generated but Schema discovery summary says "schema is empty". Any help? Webstorm 2022.2.2 and GraphQl 3.3.0

QWAQWA1 avatar Sep 23 '22 11:09 QWAQWA1

I'm also bumping into this with a small schema:

# This file was generated based on ".graphqlconfig". Do not edit manually.

schema {
    query: Query
}

interface ContentNode {
    _meta: ContentNodeMetaData
    rawJson: ContentItemJson
    rawProperty(propertyName: String!): JSON
}

type ContentItemJson {
    content: JSON
}

type ContentNodeMetaData {
    deliveryId: String!
    deliveryKey: String
    name: String
    schema: String!
}

type PageInfo {
    endCursor: String
    hasNextPage: Boolean!
    hasPreviousPage: Boolean!
    startCursor: String
}

type Query {
    allStaticPage(after: String, before: String, first: Int, last: Int): StaticPageConnection
    allWebConfig(after: String, before: String, first: Int, last: Int): WebConfigConnection
    contentNode(deliveryId: String, deliveryKey: String): ContentNode
    staticPage(deliveryId: String, deliveryKey: String): StaticPage
    webConfig(deliveryId: String, deliveryKey: String): WebConfig
}

type StaticPage implements ContentNode {
    _meta: ContentNodeMetaData
    articleContent: String
    rawJson: ContentItemJson
    rawProperty(propertyName: String!): JSON
    slug: String
    title: String
}

type StaticPageConnection {
    edges: [StaticPageEdge]!
    pageInfo: PageInfo!
}

type StaticPageEdge {
    cursor: String!
    node: StaticPage
}

type WebConfig implements ContentNode {
    _meta: ContentNodeMetaData
    rawJson: ContentItemJson
    rawProperty(propertyName: String!): JSON
    social: WebConfigSocial
}

type WebConfigConnection {
    edges: [WebConfigEdge]!
    pageInfo: PageInfo!
}

type WebConfigEdge {
    cursor: String!
    node: WebConfig
}

type WebConfigSocial {
    facebook: String
    twitter: String
}

"A JSON scalar"
scalar JSON

Corresponding .graphqlconfig:

{
  "name": "GraphQL Schema",
  "schemaPath": "schema.graphql",
  "extensions": {
    "endpoints": {
      "GraphQL Schema": {
        "url": "https://<redacted>/graphql",
        "headers": {
          "X-Src-Host": "<redacted>"
        },
        "introspect": false
      }
    }
  }
}

Error: A schema should have a 'query' operation defined with plugin version 3.3.0.

ashatch avatar Jan 16 '23 15:01 ashatch

In my case, .graphql files were not associated with the .graphql file type.

Once I associated them (right-click on the unassociated example.graphql file) I refreshed the .graphqlconfig and re-fetched the introspection schema.

After that everything started to work as before.

Xnapper-2023-01-31-13 22 13 Xnapper-2023-01-31-13 22 49

vidrepar avatar Jan 31 '23 12:01 vidrepar