1 /* 2 * Make.org Core API 3 * Copyright (C) 2020 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.technical.graphql 21 22 import cats.Id 23 import org.make.api.idea.IdeaServiceComponent 24 import org.make.core.idea.IdeaId 25 import zio.query.DataSource 26 27 import scala.concurrent.{ExecutionContext, Future} 28 29 trait GraphQLIdeaServiceComponent { 30 def ideaDataSource: DataSource[Any, GetIdea] 31 } 32 33 trait DefaultGraphQLIdeaServiceComponent extends GraphQLIdeaServiceComponent { 34 this: IdeaServiceComponent => 35 36 override val ideaDataSource: DataSource[Any, GetIdea] = { 37 def findFromIds(ideaIds: Seq[IdeaId])(ec: ExecutionContext): Future[Map[IdeaId, GraphQLIdea]] = { 38 ideaService 39 .fetchAllByIdeaIds(ideaIds) 40 .map(_.map(idea => idea.ideaId -> GraphQLIdea(idea.ideaId, idea.name)).toMap)(ec) 41 } 42 43 DataSourceHelper.one("idea-datasource", findFromIds) 44 } 45 46 } 47 48 final case class GetIdea(ids: IdeaId) extends IdsRequest[Id, IdeaId, GraphQLIdea] 49 final case class GraphQLIdea(ideaId: IdeaId, name: String)
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 40 | 39827 | 1326 - 1463 | Apply | scala.concurrent.Future.map | DefaultGraphQLIdeaServiceComponent.this.ideaService.fetchAllByIdeaIds(ideaIds).map[scala.collection.immutable.Map[org.make.core.idea.IdeaId,org.make.api.technical.graphql.GraphQLIdea]](((x$1: Seq[org.make.core.idea.Idea]) => x$1.map[(org.make.core.idea.IdeaId, org.make.api.technical.graphql.GraphQLIdea)](((idea: org.make.core.idea.Idea) => scala.Predef.ArrowAssoc[org.make.core.idea.IdeaId](idea.ideaId).->[org.make.api.technical.graphql.GraphQLIdea](GraphQLIdea.apply(idea.ideaId, idea.name)))).toMap[org.make.core.idea.IdeaId, org.make.api.technical.graphql.GraphQLIdea](scala.this.<:<.refl[(org.make.core.idea.IdeaId, org.make.api.technical.graphql.GraphQLIdea)])))(ec) | |
| 43 | 41183 | 1475 - 1527 | Apply | org.make.api.technical.graphql.DataSourceHelper.one | DataSourceHelper.one[org.make.core.idea.IdeaId, org.make.api.technical.graphql.GraphQLIdea, org.make.api.technical.graphql.GetIdea]("idea-datasource", ((ideaIds: Seq[org.make.core.idea.IdeaId]) => ((ec: scala.concurrent.ExecutionContext) => findFromIds(ideaIds)(ec)))) | |
| 43 | 31936 | 1496 - 1513 | Literal | <nosymbol> | "idea-datasource" | |
| 43 | 45249 | 1515 - 1526 | Apply | org.make.api.technical.graphql.DefaultGraphQLIdeaServiceComponent.findFromIds | findFromIds(ideaIds)(ec) |