Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info

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 become ConnectionModel[Node], ie. ConnectionModel[User]. But the problem is I don't know how to use generics with deriveObjectType. 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]](

Yann Simon

I'm very happy to share with you the first RC for the 2.0.0 release.

If we have no severe issues with it, it will become the 2.0.0 release.

:wave: I am wondering if something like Transport-level batching is possible with Sangria. Specifically, I am looking for ways I can optimize query execution (using deferred resolution) across N queries without a need to merging them into one. Thanks!
Mikkel Storgaard Knudsen
Is there any way to pass extra parameters with a DeferredResolver or a Fetcher?
The data I need to resolve is partly retrieved from an external service, but I need to pass an authtoken along to this service
It doesn't seem like passing Seq((authToken, Seq(ids)) is the right solution
Kyle H
@MikkelStorgaard I haven't worked with DeferredResolvers, but it looks like they're a class that you define, in which case that class can take the authToken in the constructor assuming you have authToken at time of construction. From example in docs, something like:
class FriendsResolver(val authToken: AuthToken) extends DeferredResolver[Any] {...}
Yann Simon

@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.

Mikkel Storgaard Knudsen
@khoberg , @yanns If I go with that, do I then have to redo the Fetchers I have now? and implement them inside Resolve?
At the moment I am just using DeferredResolver.fetchers(fooFetcher, barFetcher, ...) who has a context already.
But that context is my GraphQLService because I am using the services exposed therein to do my calls
Mikkel Storgaard Knudsen
Could I have ctx: (Option[AccessToken], GraphQLService)?
Yann Simon
Your fetchers can also use the context. Ex:
        (ctx: AuthContext, ids: Seq[UUID]) => {
Mikkel Storgaard Knudsen
@yanns In this example, are you still making a CustomDeferredResolver extending DeferredResolver and then initializing with CustomDeferredResolver.fetchers(...), or are you just using DeferredResolver.fetchers(...)
Mikkel Storgaard Knudsen

@yanns 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.)

Yann Simon
Your schema must use the AuthContext (ex: schema: Schema[AuthContext, Unit])
Mikkel Storgaard Knudsen
Okay, so far so good :)
@yanns could I do
def fooFetcher()(implicit accessTokenOption: Option[AccessToken]) = Fetcher( (ctx: GraphQLService, ids: Seq[Ids]) => ctx.listFoos(ids), )(HasId(
that way I won't be messing with the ctx
Yann Simon
No, the fetcher is instantiated once per schema. You have to use the context to propagate data related to the request
Mikkel Storgaard Knudsen
@yanns So I should probably make room for some authorisation result or the token itself in my GraphQLService, right?
Mikkel Storgaard Knudsen
In regards to GraphQLService and it being the context, I think we (my senior and I) have been "holding it wrong" until this point.
I think I have a clear idea of what to do now, so thank you so much for your help
@yanns Can we have another release? I'm eager to start using these changes sangria-graphql-org/sangria#59 =)
Yann Simon
Hi everyone. I've finally received the rights for the original github sangria organization.
All changes from the temporary fork are now replayed on the original repositories.
And I'm happy to release the v2.0.0-RC2:
@yanns great news!
Yann Simon
If you want to help the sangria ecosystem, please read
Paul Daniels
I'm curious if anyone else got federation working? I wrote some extensions to get it working for one of our internal projects, but it required creating a custom input unmarshaller (because of the _Any input).
Hello, is there any way to generate Scala stubs from a Graphql SDL, schema.graphql?
Justin Reeves
Do you have any resources for learning GraphQL, especially in the concept of moving exisiting REST API to GraphQL?
The Sangria documentation is great but there's a level of familiarity I think it assumes that I lack.
@justinallenreeves have you looked at graphQL's site?
Hi! I have a dynamically generated type, and I'd like to modify its fields at a later point in the code. Are there any recommendations on the best way to do this?
Mandeep Raj Shrestha

Hi, Has anyone tried using the class generated by scalapb(json4s) with the InputObjects for sangria.
Even after importing the libs sangria.marshalling.json4s.native._
scalapb generates the reads and we can retrieve the Reader , if needed and provide it implicitly., but even after doing so we still get the "Please consider defining an implicit instance of FromInput for it." error

sangria-graphql/sangria#202 , do we still need to explicitly create FromInput as stated in this issue

Léonard Marques
Hello everyone, sorry to bother you but I have a question regarding Sangria: I recently started a personal project and was planning to use Sangria. The thing is my project is in Scala 2.13 and I don't see 2.13 artifacts for version 1.4.2, should I consider using 2.0-RC2 instead ? And how stable is this version ? Thank you!
Is there an example of using Fetchers for something other than the primary id? I have an object that, in addition to its primary id, contains a unique id used for integration with a 3rd party service. In some cases I need to lookup objects by those 3rd-party ids, but when I do that with a Fetcher I get "Fetcher has not resolved non-optional ID" since the primary ids of the returned objects do not match the given 3rd-party ids.
Is there some way for me to say which id field on the object it should compare to for this one Fetcher?
I see, I can pass it an explicit HasId to the Fetcher that overrides the id field for that fetcher. That worked.
We're trying to use ExecutionScheme.Stream without using Subscriptions. Is that possible?
We just have a large amount of data we want to stream, but don't want to implement subscriptions.
Justin Reeves

Trying to figure out how to make input fields that have defaults defined optional?

  implicit val CompanyFilterCriteriaType = 
  implicit val CompanySortCriteriaType = 
  implicit val CompanySortQueryType = 

  val CompanyFiltersArg =
    Argument("filters", ListInputType(CompanyFilterCriteriaType), defaultValue = Seq.empty[CompanyFilterCriteria])
  val CompanySortArg: Argument[CompanySortQuery] =
    Argument("sort", CompanySortQueryType, defaultValue = CompanySortQuery(Seq.empty[CompanySortCriteria]))

looks like in the schema

filters: [CompanyFilters!]! = []
sort: CompanySort! = {fields: [], direction: Ascending}

Is the only way to change that Argument to a Argument[Option[Seq[CompanyFilterCriteria]] as well as the queried service to accept an Option[Seq[CompanyFilterCriteria]] and a default Seq.empty[CompanyFilterCriteria])
even with sort: CompanySort! being flagged as non-nullable, it uses the default if I don't supply it in the query.

It's functional and uses defaults when the variables are missing but not when they're null so I'm worried it's confusing to a user.

I have this field on my graphql schema
But when i have the Seq[X] there
Error:(65, 69) Seq[TextMessagePayload]: Field list is empty deriveObjectType[SecureContext, Seq[TextMessagePayload]](),
Is there another type of iterable I should be using > Seq?
Léonard Marques
Mh, any recommendation regarding the Sangria version I should use with Scala 2.13 ? :/
Sorry to bother you with that, but I'm really not sure what's the best option here :(