5
我有一個UserType和一個可以是Writer或Account的可用項。如何用ruby-graphql指定多態類型?
對於GraphQL我想也許我可以用這樣的UserableUnion:
UserableUnion = GraphQL::UnionType.define do
name "Userable"
description "Account or Writer object"
possible_types [WriterType, AccountType]
end
,然後確定我的用戶類型是這樣的:
UserType = GraphQL::ObjectType.define do
name "User"
description "A user object"
field :id, !types.ID
field :userable, UserableUnion
end
,但我得到schema contains Interfaces or Unions, so you must define a 'resolve_type (obj, ctx) -> { ... }' function
我曾嘗試把resolve_type放在多個地方,但我似乎無法弄清楚這一點?
現在有沒有人如何實現這個?