Ruby on rails Graphql ruby如何创建接口类型并实现它

Ruby on rails Graphql ruby如何创建接口类型并实现它,ruby-on-rails,ruby,graphql,Ruby On Rails,Ruby,Graphql,我将按照以下步骤在graphql上创建和实现接口: 这是我的密码: PaymentInterface = GraphQL::InterfaceType.define do name 'Payment' field :name, types.String field :grand_total, MoneyType field :subtotal, MoneyType field :shipping_fee, MoneyType end 这是实现先前接口的对象类型 Paypa

我将按照以下步骤在graphql上创建和实现接口:

这是我的密码:

PaymentInterface = GraphQL::InterfaceType.define do
  name 'Payment'

  field :name, types.String
  field :grand_total, MoneyType
  field :subtotal, MoneyType
  field :shipping_fee, MoneyType
end
这是实现先前接口的对象类型

PaypalPaymentType = GraphQL::ObjectType.define do
  interfaces [PaymentInterface]

  field :paypal_charge do
    type -> { MoneyType }
    type types.String
    resolve lambda { |obj, _args, _ctx|
      Hashie::Mash.new(
        currency: obj.currency,
        price: obj.paypal_charge
      )
    }
  end
end
以下是查询:

interface PaymentInterface {
    name: String
    grand_total: MoneyType
    subtotal: MoneyType
    shipping_fee: MoneyType
}
type PaypalPaymentType implements PaymentInterface {
    name: String
    grand_total: MoneyType
    subtotal: MoneyType
    shipping_fee: MoneyType
    paypal_charge: MoneyType
}
{
  purchasables {
    isService
    isProduct
    price
    ... on PaypalPaymentType {
      paypal_charge { raw formatted }
    }
  }
}
但是我不断地犯错误,以前有人有过同样的经历吗?提前谢谢

GraphQL::Schema::InvalidTypeError (Field PaymentMethod.paypal_charge is invalid: name must return String, not NilClass (nil)):

在这里,您定义了两次字段类型:

PaypalPaymentType = GraphQL::ObjectType.define do
  interfaces [PaymentInterface]

  field :paypal_charge do
    type -> { MoneyType } # <--- Defined type as Money Type
    type types.String # <--- Overwritten defined type as String
    ...
  end
end
PaypalPaymentType=GraphQL::ObjectType.define do
接口[支付接口]
字段:paypal\u charge do

键入->{MoneyType}#您遇到了什么样的错误?@tpei更新了我的问题