Skip to content
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

Mutation cannot return Array of GraphQL::ExecutionErrors #1587

Closed
ndac-todoroki opened this issue Jun 15, 2018 · 2 comments
Closed

Mutation cannot return Array of GraphQL::ExecutionErrors #1587

ndac-todoroki opened this issue Jun 15, 2018 · 2 comments

Comments

@ndac-todoroki
Copy link

ndac-todoroki commented Jun 15, 2018

Thanks to #1230 & #1231, Arrays of GraphQL::ExecutionErrors are valid returns.
Although this could be done in GraphQL::Schema::Objects, it doesn't work on GraphQL::Schema::RelayClassicMutations.

examples

https://github.com/ndac-todoroki/graphql-ruby-test
do rails server and post queries to /graphql

  • Query example
query testField {
  testField
}
  • Mutation example
mutation testMutation {
  addFoo(input: {}) {
    foo
  }
}

what is expected

Both returns errors like

{
  "data": null,
  "errors": [
    {
      "message": "one",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "testField",
        0
      ]
    },
    ...
  ]
}

what happens

The query example returns the error above as expected.
The mutation example, in contrast returns an error like this:

{
  "error": "Unexpected token T in JSON at position 0"
}

Rails console log:

Started POST "/graphql" for 127.0.0.1 at 2018-06-15 12:06:47 +0900
Processing by GraphqlController#execute as */*
  Parameters: {"operationName"=>"testMutation", "variables"=>{}, "query"=>"mutation testMutation {\n  addFoo(input:{}) {\n    foo\n  }\n}\n", "graphql"=>{"operationName"=>"testMutation", "variables"=>{"input"=>{"lessonId"=>4000}}, "query"=>"mutation testMutation {\n  addFoo(input: {}) {\n    foo\n  }\n}\n"}}
Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)



TypeError (no implicit conversion of Symbol into Integer):

app/controllers/graphql_controller.rb:10:in `execute'

environment

graphiql-rails (1.4.10)
  railties
  sprockets-rails
graphql (1.8.3)
@rmosolgo
Copy link
Owner

Thanks for the bug report! Sounds like an inconsistency in Schema::RelayClassicMutation 😖

@rmosolgo
Copy link
Owner

I don't have plans to work more on this. If you need to add multiple execution errors, you can use extras [:execution_errors] in your mutation, then

def resolve(execution_errors:, ...) 
  execution_errors.add(GraphQL::ExecutionError.new(...))
  execution_errors.add(GraphQL::ExecutionError.new(...))
end 

Let me know if that doesn't work! You can find the API docs for that object here: https://graphql-ruby.org/api-doc/1.9.11/GraphQL/Query/Context/ExecutionErrors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants