-
Notifications
You must be signed in to change notification settings - Fork 95
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] Merged schemas conflict. Query type tried to redefine existing Query type. #201
Comments
Hi Alex. Thanks for trying out the alpha. The plugin appears to have discovered a definition of the Query type in more than one location. Please review the docs linked from https://github.com/jimkyndemeyer/js-graphql-intellij-plugin/releases/tag/2.0.0-alpha-3 about how schema discovery works. Note for example, that some npm packages include graphql definitions that may cause conflicts if they are unintentionally included in schema discovery. If you still encounter an issue, please link/attach a small project that reproduces the issue. Best regards, |
Exactly. But this shouldn't be the issue. Here the repo: |
Hi Alex. Ah, I didn't catch that schema stitching was involved. For this use case the plugin can't automatically discover what your effective schema is using GraphQL files containing SDL since schema stitching can rename types, move fields etc. What you'll need to do is to use introspection to let the plugin discover your fully stitched schema, and ensure that your config only includes the files where you will be consuming the stitched schema, e.g. in your components. So, depending on your project structure you may need .graphqlconfig files for:
You should be able to make this work. See https://github.com/prisma/graphql-config#specifying-includesexcludes-files Once you've configured "A+B" with the URL for your stitched endpoint, you can click the green arrow in the editor gutter in the config editor, and it will write the introspection result to the file specified in "schemaPath". Then make sure that you use "include"/"exclude" so "A" and "B" are not discovered where you'll be using the stitched schema. Hope that helps. Best regards, |
Thanks for help. I've implemented the flow you described - #201 (comment) Seems like 'Query' error is gone but there is another error now. User
{
"includes": ["../country/*.graphql", "*.graphql"]
}
type Query {
user(id: ID!): User
users: [User]
}
type User {
id: ID!
email: String!
username: String!
firstName: String
lastName: String
phone: String
country: Country!
} Country
{
"includes": ["*.graphql"]
}
type Country {
id: ID!
name: String!
iso2: String!
iso3: String!
isoNum: Int!
phoneCode: Int!
isBlocked: Int!
} Repo is the same: |
Found solution. {
"projects": {
"config": {
"includes": ["./config/*.graphql"]
},
"user": {
"includes": ["./country/*.graphql", "./user/*.graphql"]
}
}
} |
Ok. Another issue popped up. If any of components depends on the type of another component - Query error will be thrown as well. Example:
{
"projects": {
"user": {
"includes": ["./country/*.graphql", "./user/*.graphql"]
},
"trader": {
"includes": ["./user/*.graphql", "./trader/*.graphql"]
}
}
}
type Query {
user(id: ID!): User
users: [User]
}
type Mutation {
register(input: RegisterInput!): User
}
input RegisterInput {
email: String!
password: String!
}
type User {
id: ID!
email: String!
username: String!
firstName: String
lastName: String
phone: String
country: Country!
}
type Query {
trader(id: ID!): Trader
traders: [Trader]
}
type Mutation {
register(input: TraderRegisterInput!): Trader
}
type Trader {
id: ID!
user: User!
}
input TraderRegisterInput {
email: String!
password: String!
currency: String!
} Repo is the same: Maybe we could think about more simple and more maintainable way to handle merged schemas. Maybe some flag in settings that will not check |
Ok. So I found the proper way to handle this.
{
"schemaPath": "./root.graphql",
"projects": {
"app": {
"includes": [
"./config/*.graphql",
"./country/*.graphql",
"./user/*.graphql",
"./trader/*.graphql"
]
}
}
}
scalar JSON
type Query
type Mutation
extend type Query {
trader(id: ID!): Trader
traders: [Trader]
}
extend type Mutation {
registerTrader(input: TraderRegisterInput!): Trader
}
type Trader {
id: ID!
user: User!
}
input TraderRegisterInput {
email: String!
password: String!
currency: String!
} Repo is the same: |
@ph55 If I may ask how did you combine your graphql files into one schema? I'm currently using https://github.com/prisma/graphql-import but they don't seem to support extend. So I can get the plugin happy with your suggestion but then graphql-import stops working as they just skip over all types that have extend. |
@ktersius Sure. I'm using NestJS framework which handles schema stitching. I think it's supported by default in Apollo graphql server. |
@ph55 Thanks. I ended up using https://github.com/Urigo/merge-graphql-schemas which seems to do the job. |
i don't think this is feasible for me as it's just too much config work |
Updated to latest version for string literals.
But now getting error for
Query
override.I'm using different schemas files that then being merged by
grpahql-tools
.Version and Environment Details
Operation system:
macOS 10.14.2
IDE name and version:
PhpStorm 2018.1.7
Plugin version:
2.0.0-alpha-3
Expected Behaviour
Shouldn't throw error
Actual Behaviour
user.gql
Probably conflicting
config.gql
:Doesn't work neither with
.graphqlconfig
:Nor with scope:
The text was updated successfully, but these errors were encountered: