Hello, I'm working on a Many-to-Many relation with Sangria and Slick.
I have 3 objects: Role, Permission and RolePermission (a mapping table)
case class Role(id: Long, name: String)
case class Permission(id: Long, name: String)
case class RolePermission(id: Long, roleId: Long, permissionId: Long)
So far, I figured out how to define the relation:
val permissionsByRoleId = Relation[Permission, (RolePermission, Permission), Long]("permissionsByRoleId", tmp ⇒ Seq(tmp._1.roleId), _._2)
but still working on the fetcher and how to add the right field to Role Schema, so that I could retrieve the Role's permissions passing by the intermediate table.
Any help ?
a simple example would help.
QueryRenderer.render(graphqlMacro, QueryRenderer.Compact)
but it doesn't generate a query like it comes from a client. I'm trying to run an integration test
@asafary add sangria-slowlog to the dependencies libraryDependencies += "org.sangria-graphql" %% "sangria-slowlog" % "0.1.8"
and attach the provided middleware extension to the executor
Executor.execute(schema, query,
middleware = SlowLog(logger, threshold = 10 seconds) :: Nil)
It will respond with some kind of profiliing info.. I hope it helps, if not, it's a good base to make your own profiler which will cover your needs... :)
@travisbrown https://github.com/schleumer/sangria-ambiguous-reference
You know if this still a thing? Would help if i create an issue about it?
Hi all, does anyone have an answer for this question asked a while ago?
hi all, I'm trying to implement Pagination with Sangria, so I was considering to use a structure like this:
case class ConnectionModelEdge[T]( node: T, cursor: UUID, ) case class ConnectionModelPageInfo( endCursor: UUID, hasNextPage: Boolean, ) case class ConnectionModel[T]( totalCount: Int, edges: List[ConnectionModelEdge[T]], pageInfo: ConnectionModelPageInfo, )
in other words, any
List[Node]
Queries should becomeConnectionModel[Node]
, ie.ConnectionModel[User]
. But the problem is I don't know how to use generics withderiveObjectType
. Even if I created separate implicit val for each and every type I used (ie.deriveObjectType[ConnectionContext, ConnectionModel[User]]
), Sangria rises an error:Error:(32, 67) Can't find suitable GraphQL output type for T. If you have defined it already, please consider making it implicit and ensure that it's available in the scope. deriveObjectType[ConnectionContext, ConnectionModelEdge[User]]( Error:(32, 67) not enough arguments for method implicitly: (implicit e: sangria.macros.derive.GraphQLOutputTypeLookup[T])sangria.macros.derive.GraphQLOutputTypeLookup[T]. Unspecified value parameter e. deriveObjectType[ConnectionContext, ConnectionModelEdge[User]](
I'm very happy to share with you the first RC for the 2.0.0 release.
https://github.com/sangria-graphql-org/sangria/releases/tag/v2.0.0-RC1
If we have no severe issues with it, it will become the 2.0.0 release.
class FriendsResolver(val authToken: AuthToken) extends DeferredResolver[Any] {...}
@MikkelStorgaard You can pass an AuthContext:
object DeferredReferenceResolver extends DeferredResolver[AuthContext] {
def resolve(deferred: Vector[Deferred[Any]], ctx: AuthContext, queryState: Any)(implicit ec: ExecutionContext): Vector[Future[Any]] = {
and give the DeferredReferenceResolver
to the Executor
.
@yanns https://pastebin.com/WbnyvFqC I currently have fooFetcher , but I need to be able to have fooFetcherBetter. however I don't know how to get the implicit accessTokenOption into the fetcher from here.
(disclaimer; I have a background in functional programming, but I have only used Scala/Sangria/... for a bit more than a month, so there might be some Scala features here that I am not aware of.)
def fooFetcher()(implicit accessTokenOption: Option[AccessToken]) = Fetcher(
(ctx: GraphQLService, ids: Seq[Ids]) => ctx.listFoos(ids),
)(HasId(_.id))
?