graphiql: "message": "Unknown operation named \"undefined\"."

I’m testing / debugging resolvers using GraphiQL. At times, seemingly prompted by restarting the backend app, I’ll start getting responses like this:

{
  "errors": [
    {
      "message": "Unknown operation named \"undefined\"."
    }
  ]
}

Restarting the app or refreshing the GraphiQL page do not fix the error. However, cutting the query and pasting it back into the query window seems to resolve the issue.

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 33
  • Comments: 25 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I’m not exactly sure what the root issue is, but I think this is due to saving state between runs. localStorage coerces everything to a String before saving it, so setting undefined results in getting "undefined".

Hello, same issue using this tutorial http://docs.graphene-python.org/projects/sqlalchemy/en/latest/tutorial/ sorry if off-topic

Just confirming that I’m having the same problem @kastermester mentioned here. It’s pretty annoying and really easy to reproduce, you just need to: run a unnamed mutation, refresh the page and run it again. I’m using the graphiql that graphql-server-express renders, which seems to be at 0.10.2.

I still hit this issue when using unnamed queries/mutations/subscriptions. The issue arises when entering a query, like:

mutation {
  someMutation(input: {
    clientMutationId: ""
  }) {
    clientMutationId
  }
}

If one enters this query, and executes it - everything works as intended. From here, a second reload will yield the error. If doing the exact same query but naming the operation, like this:

mutation MyMutation {
  someMutation(input: {
    clientMutationId: ""
  }) {
    clientMutationId
  }
}

Then no error occours.

EDIT: This is GraphIQL 0.10.1

For graphene-python users who can afford patching the python lib for development process, there is a simple solution: in the file graphql/execution/utils.py at the beginning of init func of a class ExecutionContext you can paste something like

if operation_name == 'undefined':
    operation_name = None

Just hitting F5 reproduces this error. For now, workaround is Ctrl+A, Ctrl+X, Ctrl+V and query runs normal.

this code in example/index.html should guard from such a case.

@asiandrummer You need to propagate this change to express-graphql and other servers. For example, see this: https://github.com/graphql/express-graphql/blob/master/src/renderGraphiQL.js#L86-L89