iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌊

Resolving 'Second definition of mutation(...)' Error in Rails + GraphQL

に公開

Introduction

I struggled with this for a bit, so I'm writing this down as a memo.

Environment

  • Ruby on Rails 7.0.3.1
  • GraphQL Ruby 2.0.12

Situation

When calling the Rails API from a GraphQL client, the following error is displayed.

mutation': Second definition of 'mutation(...)' (GraphqlDevise::Types::MutationType) is invalid

As the error suggested, I looked for a duplicate definition of GraphqlDevise::Types::MutationType, but I couldn't find one.

Solution

In most cases, the cause is a syntax error within the Ruby on Rails project. You can resolve it by searching thoroughly for syntax errors or by introducing RuboCop to fix them one by one.

$ bundle exec rubocop --parallel

That's all.

Discussion