Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object ExampleViewerSchema {
- case class User(id: String)
- class FriendsService {
- def list(user: User): List[User] = List() // Actually filter based on your data model
- }
- class UserService {
- def authenticate: User = User("1") // Actually get a user
- }
- case class ServiceManager(friendsService: FriendsService, userService: UserService)
- case class MyContext(user: Option[User], serviceManager: ServiceManager)
- val UserType = ObjectType[MyContext, User](
- "User",
- fields = fields[MyContext, User](
- Field(
- "id",
- StringType,
- resolve = ctx => ctx.value.id
- )
- )
- )
- val ViewerType: ObjectType[MyContext, Unit] = ObjectType(
- "Viewer",
- "The current, authenticated user.",
- fields = fields[MyContext, Unit](
- Field(
- "tastings",
- ListType(UserType),
- Some("List all of the friends for a user."),
- resolve = ctx => ctx.ctx.serviceManager.friendsService.list(ctx.ctx.user.get)
- )
- )
- )
- val ViewQuery = fields[MyContext, Unit](
- Field(
- "viewer",
- ViewerType,
- Some("Information in the app scoped to the requesting user."),
- resolve = ctx => UpdateCtx(ctx.ctx.serviceManager.userService.authenticate) { user =>
- ctx.ctx.copy(user = Some(user))
- }
- )
- )
- val QueryType: ObjectType[MyContext, Unit] = ObjectType("Query",
- ViewQuery
- )
- val schema = Schema(QueryType)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement