Graphql + Rails 5: update

Asked

Viewed 36 times

0

I’m having some problems when updating table data with Graphql.

Situation: I need to send the field description and the status amendment. However, it will not always be necessary to send both.

module Mutations
  class UpdateTask < BaseMutation
    argument :id, ID, required: true
    argument :description, String, required: false
    argument :status, String, required: false
    type Types::TaskType
    def resolve(id:, description:, status:)
      task = Task.find(id)
      task.update(description: description, status: status)
    end
  end
end

When I submit, it updates the fields but returns this error:

        Failed to implement Task.id, tried:

        - `Types::TaskType#id`, which did not exist
        - `TrueClass#id`, which did not exist
        - Looking up hash key `:id` or `"id"` on `true`, but it wasn't a Hash

        To implement this field, define one of the methods above (and check for typos)

How could I solve this mistake?

1 answer

1


Friend, the error is not because you are passing id, Description and status in the parameters as a hash and not as a symbol. Where: Hash you have { key: value }. In your method, maybe just change this:

def resolve(:id, :description, :status)
  task = Task.find(id)
  task.update(description: description, status: status)
end

Obs: to be sending the object task for a view for example, be sure to include the @: @task. I hope it helps!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.