graphql-ruby: Mutations not being loaded

Hello community,

I’m reaching to this section as I have been working on several weeks to understand whether this is potentially a bug.

The piece of code below regards to a login mutation. It takes email and password, then ruby-graphql should return a token. The actual values for email and password are passed as variables.

mutation {
  token: login(
    email: "...",
    password: "..."
  )
}

In production environment GraphQL spills an odd error regarding mutations not being configured.

{
  "errors": [
    {
      "message": "Schema is not configured for mutations",
      "locations": [
        {
          "line": 1,
          "column": 1
        }
      ],
      "path": [
        "mutation"
      ],
      "extensions": {
        "code": "missingMutationConfiguration"
      }
    }
  ],
  "extensions": {}
}

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@cassiopagnoncelli sorry to hear that you have to redo the schema from scratch. Well at least the problem’s gone 😃

I’m going to close the issue, if you bump into some issue like this 🤞 in the future and discover a gotcha, be glad to take a PR to document it.

@nekogami No not really, turns out that the query and mutation are well-formed, it actually returns a value, look:

{
  "data": {
    "token": "eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7ImlkIjoxNjQ1MywibWVyY2hhbnRJZCI6MTE4NSwiZW1haWwiOiJub2VseXBpY29sbG9AZ21haWwuY29tIiwicGVybWlzc2lvbnMiOm51bGwsIm5hbWUiOiJOb2VseSBQaWNvbGxvIn0sImV4cCI6MTU2NzEzMTY3N30.DosoZV5f6_uRdERR9p5paRVjYBu5Fz3H137uslUGel8"
  },
  "extensions": {}
}

I just run it in my machine under Docker on development environment. When I deploy to production, mutations won’t work. Types::QueryType is recognized and queries work perfectly, but not for Types::MutationType as they aren’t even loaded.

I’m trying to think what could be different in development vs. production. One thing that stood out is parallelism – are you using a multi-threaded or multiprocess server like Puma or Phusion Passenger? I wonder if a process could somehow fork before the schema is totally booted, and then the forked schema isn’t all set up properly.

I don’t really have a clear suggestion, except something that sometimes helps with these loading issues. Try adding at the very bottom of api_schema.rb:

# Ensure that the schema is booted eagerly, instead of before the first query 
ApiSchema.graphql_definition 

It might work 😅 . (Longer term, I’m trying to simplify schema boot over at #2363.)

Hey @cassiopagnoncelli I like to help but need more information about your schema setup. Specifically the call site where you have

class MySchema < GraphQL::Schema
  # Required:
  query Types::Query
  # Optional:
  mutation Types::Mutation
  subscription Types::Subscription
end

And your equivalent of Types::MutationType class.

From the error, it looks like it might be broken right at the Schema def level.