I am looking to do something similar to what is done in the graphql tutorial: https://graphql.org/learn/queries/#arguments
I want to pass feet/meters to a scaler field to transform the result that is returned.
{
  human(id: "1000") {
    name
    height(unit: FOOT)
  }
}
I can't figure out how to do that in ruby using graphql-ruby.
I currently have a type that looks like:
class Types::Human < Types::BaseObject
  field :id, ID, null: false
  field :height, Int, null: true do
     argument :unit, String, required: false
  end
  def height(unit: nil)
  #what do I do here to access the current value of height so I can use unit to transform the result?
  end
end
I have found that the resolver method (height) is called for every instance that is returned... but I don't know how to access the current value.
Thanks
 
                        
When you define a resolving method inside of your type definition Graphql Ruby assumes that that method will resolve the value. So at the time your current method
def height(unit: nil)is ran it doesn't know what the current height value is because it is expecting you to define it.Instead what you would want to do is move the resolving method to the model / object returned for the
Humantype. For example, in rails you might do this:GraphQL Ruby will then call
.heighton the instance of human that is passed to it.