尝试与桑格利亚汽酒和Slick合作。他们俩都是新手。
我有一堆共享公用字段列表的表。 Slick对此的表示如下:
case class CommonFields(created_by: Int = 0, is_deleted: Boolean = false)
trait CommonModel {
def commonFields: CommonFields
def created_by = commonFields.created_by
def is_deleted = commonFields.is_deleted
}
case class User(id: Int,
name: String,
commonFields: CommonFields = CommonFields()) extends CommonModel
光滑的桌子
abstract class CommonTable [Model <: CommonModel] (tag: Tag, tableName: String) extends Table[Model](tag, tableName) {
def created_by = column[Int]("created_by")
def is_deleted = column[Boolean]("is_deleted")
}
case class CommonColumns(created_by: Rep[Int], is_deleted: Rep[Boolean])
implicit object CommonShape extends CaseClassShape(
CommonColumns.tupled, CommonFields.tupled
)
class UsersTable(tag: Tag) extends CommonTable[User](tag, "USERS") {
def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
def name = column[String]("NAME")
def * = (id,
name,
CommonColumns(created_by, is_deleted)) <> (User.tupled, User.unapply)
}
val Users = TableQuery[UsersTable]
问题出在Graphql上:
lazy val UserType: ObjectType[Unit, User] = deriveObjectType[Unit, User]()
当我尝试使用namedObjectType宏创建UserType时,它抱怨
Can't find suitable GraphQL output type for <path>.CommonFields. If you have defined it already, please consider making it implicit and ensure that it's available in the scope.
[error] lazy val UserType: ObjectType[Unit, User] = deriveObjectType[Unit, User](
如何告诉Sangria / Graphql如何处理此嵌套字段列表(来自CommonFields)?
请帮助。
答案 0 :(得分:1)
您正在派生用户的类型,但用户还具有尚未派生的CommonFields。因此,它无法找到CommonFields的Type信息。两者都派生,并使派生对CommonFields隐含。
implicit val CommonFieldsType: ObjectType[Unit, CommonFields] = deriveObjectType[Unit, CommonFields]
implicit val UserType: ObjectType[Unit, User] = deriveObjectType[Unit, User]