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

Merging schema causes the error "... tried to redefine existing type Mutation"

Open anisebamford opened this issue 3 years ago • 10 comments

Describe the bug When using the graphql-tools mergeSchemas function and presumably other tools that provide the same function, the error "... tried to redefine existing type Mutation" is set when mutations are defined in separate locations.

To Reproduce

  1. Create two mutations in separate statements.
  2. Use graphQlTools.mergeSchemas() to merge the two mutations.
  3. Observe the error.

Expected behavior An option should be provided to disable this error.

anisebamford avatar Oct 13 '20 18:10 anisebamford

I had exactly same problem, but I found this example and everything works great now! For more info please take a look into docs.

slaviczavik avatar Nov 09 '20 17:11 slaviczavik

Add the generated schema as Excluded with right click and Mark as > Excluded

RichardLindhout avatar Apr 29 '21 19:04 RichardLindhout

I have dozens of files that define mutations or queries with

gql`
  type Mutation {
    zhuliDoTheThing(...) Varrik
  }
`;

I do not have generated schema.

The plugin flags all of them with errors. Excluding the majority of my schema removes the usefulness of the plugin, and I'm not restructuring my project to make this plugin happy. I have instead removed the plugin.

anisebamford avatar Apr 29 '21 23:04 anisebamford

@bumpusfrancus I'm preparing a new v3 release now, where it would be possible to disable these inspections (type redefinitions and field redefinitions) completely or suppress on a file/definition level with a comment. It's a bit experimental and not guaranteed to work excellent because the release is huge, but it should help in a case like yours. So, give it a try when it will be released pls 🙏 . I hope a release will happen the next week.

vepanimas avatar Apr 29 '21 23:04 vepanimas

Thanks @vepanimas. I was really impressed with how smoothly the plugin worked in general, and if my project had a more conventional structure I would have loved to use it. Thanks for all your hard work.

anisebamford avatar Apr 29 '21 23:04 anisebamford

We're facing the same issue. Did anyone manage to solve it?

bfelbo avatar Dec 09 '21 17:12 bfelbo

Hi @bfelbo! You can try to disable that kind of error completely now. Conflicting declarations will be merged under the hood and it should work:

type redefintions

vepanimas avatar Dec 09 '21 18:12 vepanimas

That's perfect, thanks for the quick response @vepanimas!

Is there a way to add this into the GraphQL config file? Otherwise anyone else on the project will have to go edit this in their settings.

bfelbo avatar Dec 09 '21 18:12 bfelbo

@bfelbo in general, settings (e.g., inspection profiles, code style) are under the .idea folder. So you can commit inspectionProfiles to the repo and you will have the same configuration for the whole team.

commit settings

vepanimas avatar Dec 09 '21 18:12 vepanimas

Ah, that makes sense. I'm just starting to use IntelliJ IDEs so that was likely a noob question. Thanks for explaining this in detail!

bfelbo avatar Dec 10 '21 15:12 bfelbo