Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4619

What is the difference between :id, id: and id in ruby?

$
0
0

I am trying to build a ruby on rails and graphQL app, and am working on a user update mutation. I have spent a long time trying to figure it out, and when I accidentally made a typo, it suddenly worked.

The below is the working migration:

module Mutations  class UpdateUser < BaseMutation    argument :id, Int    argument :first_name, String    argument :last_name, String    argument :username, String    argument :email, String    argument :password, String    field :user, Types::User    field :errors, [String], null: false    def resolve(id:, first_name:, last_name:, username:, email:, password:)      user = User.find(id)      user.update(first_name:, last_name:, username:, email:, password:)      { user:, errors: [] }    rescue StandardError => e      { user: nil, errors: [e.message] }    end  endend

The thing I am confused about is when I define the arguments, they are colon first: eg :id or :first_name

When I pass them to the resolve method they only work if they have the colon after: eg id: or first_name:

When I pass the variables to the update method, they use the same syntax of colon after, for all variables other than ID. For some reason, when I used id: it was resolving to a string "id", and using colon first :id was returning an undefined error.

It is only when I accidentally deleted the colon, and tried id that it actually resolved to the passed through value.

My question for this, is why and how this is behaving this way? I have tried finding the answer in the docs, and reading other posts, but have been unable to find an answer.

Please someone help my brain get around this, coming from a PHP background, ruby is melting my brain.


Viewing all articles
Browse latest Browse all 4619

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>