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

[v2] Unknown fragment spread "..." #218

Closed
blacksmoke26 opened this issue Mar 12, 2019 · 16 comments
Closed

[v2] Unknown fragment spread "..." #218

blacksmoke26 opened this issue Mar 12, 2019 · 16 comments

Comments

@blacksmoke26
Copy link

blacksmoke26 commented Mar 12, 2019

Hi Jim,

I am getting a warning while try to use fragment in a query (which executes without any error):

image

fragment basicInfo on Bathroom {
  name
  slug
}

query {
  bathrooms (pager: {
    limit: 1,
    type: NUMBER
  }) {
    nodes {
      ...basicInfo
    }
  }
}

But no error return after fetch data:

{
  "data": {
    "bathrooms": {
      "nodes": [
        {
          "name": "1",
          "slug": "1"
        }
      ]
    }
  }
}

Details:

PhpStorm 2019.1 EAP
Build #PS-191.6014.13, built on March 6, 2019
PhpStorm EAP User
Expiration date: April 5, 2019
JRE: 1.8.0_202-release-1483-b31 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 8.1 6.3
---
JS GraphQL: v2.0.0-alpha-8

P.S. Please let me know if you need more details.

Thanks!

@jimkyndemeyer
Copy link
Collaborator

Hi Junaid.

Can you confirm that you're only seeing this issue in scratch files, and not with files picked up as part of the regular project source files?

@blacksmoke26
Copy link
Author

Yes Jim, Only in a scratch file.

@blacksmoke26
Copy link
Author

blacksmoke26 commented Mar 12, 2019

Now facing another issue here:

.graphqlconfig File (No errors)
image

The Files structure:
image

The schema file is placed with it:
image

Now if I remove "node/graphql/schema/**/*.graphql" from exclude:

"excludes": [
  "node/graphql/schema/**/*.graphql"
],

to

"excludes": [
],

I get a load of following warnings:
image

Error: The input value type 'QueryFilterEnum' is not present when resolving type 'FilterQueryInput' [@3:1]
File inputs.graphql

input FilterQueryInput {
  query: String!
  column: String
  rule: QueryFilterEnum
}

image

Error: 'Query' type [@46:1] tried to redefine existing 'Query' type [@40:1]
File me.graphql

type Query {
  me: Me! @auth @cost(complexity: {min: 2})
  myLoginHistory: MyloginHistory! @auth @cost(complexity: {min: 2})
}

image

Maybe due to split schema into multiple files?

I am using graphql-import

@blacksmoke26
Copy link
Author

I figured it out.

The reason is: both schema-graphql.json and *.graphql files are present at the same time.

Both contain identical contents, so that's why!

@jimkyndemeyer
Copy link
Collaborator

Fragment definitions will be picked up in scratch files as well for the upcoming beta-1 release.

Best regards,
Jim.

@blacksmoke26
Copy link
Author

Thank you, Jim, for your great efforts!

@dandrei
Copy link

dandrei commented Sep 4, 2019

Hello everyone,

I have an issue that prints a similar message.

Versions:

  • IDE: WebStorm 2019.2.1
  • JS GraphQL: 4.7

Use case:

A bunch of .graphql files (each defining type Query and type Mutation) that I merge with mergeSchemas.

The GraphQL tab in the IDE, under "Schema errors", shows errors such as:

  • 'Query' type [@8:1] tried to redefine existing 'Query' type [@1:1]
  • 'Mutation' type [@15:1] tried to redefine existing 'Mutation' type [@88:1]
    etc.

Here's my .graphqlconfig:

{
  "name": "GraphQL Schema",
  "includes": [
    "*.graphql"
  ],
  "extensions": {
    "endpoints": {
      "GraphQL Endpoint": {
        "url": "http://localhost:8080/graphql",
        "headers": {
          "user-agent": "JS GraphQL"
        },
        "introspect": false
      }
    }
  }
}

Any way to fix this? Thanks!

@jimkyndemeyer
Copy link
Collaborator

jimkyndemeyer commented Sep 4, 2019

@dandrei By merging you're essentially redeclaring the Query and Mutation types in your project.

You need to configure schema discovery such that the two logical schemas don't "step on each others toes". You can do this by placing the generated schema in a separate folder with its own .graphqlconfig, and then excluding it from your current .graphqlconfig using the excludesarray.

More info on schema discovery is available at https://jimkyndemeyer.github.io/js-graphql-intellij-plugin/docs/developer-guide#project-structure-and-schema-discovery

@blacksmoke26
Copy link
Author

@dandrei Yeah that's the valid issue. When you split your schema into multiple files. This error always popup.

@jimkyndemeyer I am facing the same issue. Do you plan to fix this issue?

P.S. I am using the following library to split my schema into chunks (later combined on runtime):
https://github.com/prisma/graphql-import

@jimkyndemeyer
Copy link
Collaborator

@blacksmoke26 To your question "Do you plan to fix this issue?". I'm not sure what kind of "fix" you are expecting here? There's countless ways to implement a GraphQL endpoint, and this plugin supports two spec-compliant ways of discovering your schema: introspection and GraphQL SDL controlled by graphql-config includes/excludes.

To my knowledge this allows you to split up your GraphQL files however you want, and combine them with your choice of runtime, given that you use graphql-config to produce valid schemas/type registries such that types are not redefined.

@blacksmoke26
Copy link
Author

Thanks, @jimkyndemeyer for your reply.

I am excepting at least disable the warning or Inspection?

image

Inspections > Graphql > [x] Warn about duplicate types declaration.

@jimkyndemeyer
Copy link
Collaborator

jimkyndemeyer commented Sep 6, 2019

@blacksmoke26 It's more complicated than a simple inspection. A lot of the features in the plugin depend on types being uniquely defined within the scope of a schema. Without that assumption features such as go to definition, completion, error highlighting, and find usages don't work or make sense. All these features require that your type is defined once in a source code scope, and that a valid type registry can be built for validation and completion.

Similar restrictions and assumptions underly the language tooling for other typed languages on the IntelliJ platform, so it's not unique to this plugin.

From what I know of graphql-config and the use of includes/excludes you should be able to properly scope your "authoring/split" schema graphql files and the resulting "merged" schema such that they are separate scopes and valid.

@jahudka
Copy link

jahudka commented Dec 2, 2019

@jimkyndemeyer the issue is that graphql-import allows me to do this:

# src/graphql/users/schema.graphql
type User {
  id: ID!
  name: String!
}

type Query {
  users: [User!]!
  user(id: ID!): User!
}
# src/graphql/messages/schema.graphql
type Message {
  id: ID!
  from: User!
  to: User!
  date: String!
  text: String!
}

type Query {
  messages: [Message!]!
  messagesFrom(userId: ID!): [Message!]!
  messagesTo(userId: ID!): [Message!]!
}

type Mutation {
  sendMessage(to: ID!, text: String!): Message
}

Basically it allows me to not only split the definitions of the types into separate files kept alongside the appropriate resolvers and other code related to a specific group of endpoints, it also allows me to keep the definitions of the operations for any given group of endpoints alongside the types. This does wonders for code organisation and refactoring. I know I could still keep the User and Message type definitions in separate files, but then I'd need to have separate src/graphql/query.graphql and src/graphql/mutation.graphql files which would be just huge and all-round awful to work with.

@jimkyndemeyer
Copy link
Collaborator

@jahudka Have you tried the following:

# operations.graphql
type Query
type Mutation
# other-schema-files.graphql
extend type Query {
 operationName: OperationType
}

extend type Mutation {
 operationName: OperationType
}

This validates according to the GraphQL spec, and should be supported by the plugin.

The same extends approach is used by Apollo to add client fields to the Query type and other types: https://github.com/jimkyndemeyer/graphql-config-examples/blob/master/extend-client-fields-and-directives/client-schema-extensions.js

@jahudka
Copy link

jahudka commented Dec 2, 2019

@jimkyndemeyer unfortunately, I have tried it: ardatan/graphql-import#42

@digitlninja
Copy link

Im getting this same error when using simple .graphql files with nestJS which support splitting.

users.graphql
image

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

No branches or pull requests

5 participants