Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sangria.macros.derive._
- import sangria.schema._
- import graphql.OutputTypes._
- trait Execution {
- this: CatalogRepo =>
- // ... other entities
- def course(id: Int):Option[Course] = course(id) // call to backend
- def courses(ids: Option[Seq[Int]], limit: Option[Int], offset: Option[Int], search: Option[String]): List[Course] = courses(ids, limit, offset, search) // call to backend
- def teachingCenter(id: Int):Option[TeachingCenter] = teachingCenter(id) // call to backend
- def teachingCenters(ids: Option[Seq[Int]], limit: Option[Int], offset: Option[Int], search: Option[String]): List[TeachingCenter] = teachingCenters(ids, limit, offset, search) // call to backend
- }
- object SchemaDefinition {
- val QueryType = ObjectType("Query", fields[Ctx, Unit](
- // ... other entities
- Field("course", OptionType(CourseType),
- description = Some("Returns a Course with specific `id`."),
- arguments = Id :: Nil,
- resolve = c ⇒ c.ctx.execution.course(c arg Id) ),
- Field("courses", ListType(CourseType),
- description = Some("Returns a list of all available Courses."),
- arguments = Limit :: Offset :: Search :: Nil,
- resolve = c ⇒ c.ctx.execution.courses(None, c arg Limit, c arg Offset, c arg Search) )
- , Field("teachingCenter", OptionType(TeachingCenterType),
- description = Some("Returns a TeachingCenter with specific `id`."),
- arguments = Id :: Nil,
- resolve = c ⇒ c.ctx.execution.teachingCenter(c arg Id) ),
- Field("teachingCenters", ListType(TeachingCenterType),
- description = Some("Returns a list of all available TeachingCenters."),
- arguments = Limit :: Offset :: Search :: Nil,
- resolve = c ⇒ c.ctx.execution.teachingCenters(None, c arg Limit, c arg Offset, c arg Search)
- ))
- // Ctx is defined in OutputTypes.scala
- val ExecutionType = deriveContextObjectType[Ctx, Execution, Unit](_.execution)
- val schema = Schema(QueryType, Some(ExecutionType), Some(SubscriptionType))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement