如何通过 GraphQL Ruby 获取回形针图像 URL



我正在尝试通过 GraphQL Ruby gem 使项目的回形针缩略图变体可用:

app/graphql/types/item_type.rb

class Types::ItemType < Types::BaseObject
  description 'An item'
  field :title, String, null: false
  field :thumbnail_image, String, null: true
  def thumbnail_image
    item.image.url(:thumb_2x)
  end
end

这只会导致以下错误:

"message": "undefined local variable or method `item' for #<Types::ItemType:0x00007ff3f1dbc4e0>"

让它发挥作用的正确方法是什么?我需要旋转变压器吗?

想通了,我需要这样做:

def thumbnail_image
  object.image.url(:thumb_2x)
end

最新更新