Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import sangria.macros.derive._
  2. import sangria.schema._
  3.  
  4. import graphql.OutputTypes._
  5.  
  6.  
  7. trait Execution {
  8. this: CatalogRepo =>
  9.  
  10. // ... other entities
  11.  
  12. def course(id: Int):Option[Course] = course(id) // call to backend
  13.  
  14. 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
  15.  
  16. def teachingCenter(id: Int):Option[TeachingCenter] = teachingCenter(id) // call to backend
  17.  
  18. 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
  19. }
  20.  
  21. object SchemaDefinition {
  22.  
  23. val QueryType = ObjectType("Query", fields[Ctx, Unit](
  24.  
  25. // ... other entities
  26.  
  27. Field("course", OptionType(CourseType),
  28. description = Some("Returns a Course with specific `id`."),
  29. arguments = Id :: Nil,
  30. resolve = c ⇒ c.ctx.execution.course(c arg Id) ),
  31.  
  32. Field("courses", ListType(CourseType),
  33. description = Some("Returns a list of all available Courses."),
  34. arguments = Limit :: Offset :: Search :: Nil,
  35. resolve = c ⇒ c.ctx.execution.courses(None, c arg Limit, c arg Offset, c arg Search) )
  36.  
  37. , Field("teachingCenter", OptionType(TeachingCenterType),
  38. description = Some("Returns a TeachingCenter with specific `id`."),
  39. arguments = Id :: Nil,
  40. resolve = c ⇒ c.ctx.execution.teachingCenter(c arg Id) ),
  41.  
  42. Field("teachingCenters", ListType(TeachingCenterType),
  43. description = Some("Returns a list of all available TeachingCenters."),
  44. arguments = Limit :: Offset :: Search :: Nil,
  45. resolve = c ⇒ c.ctx.execution.teachingCenters(None, c arg Limit, c arg Offset, c arg Search)
  46. ))
  47.  
  48. // Ctx is defined in OutputTypes.scala
  49. val ExecutionType = deriveContextObjectType[Ctx, Execution, Unit](_.execution)
  50.  
  51. val schema = Schema(QueryType, Some(ExecutionType), Some(SubscriptionType))
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement