Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Michael Xavier
@michaaelsx_gitlab

can someone help me with the mutation?

Schema

  implicit val inComercioType = deriveObjectType[DataRepo, comercio]()

  val ComercioInObject = {
    InputObjectType(
      name = "Insert Comercio",
      description = "",

      List(
        InputField(
          name = "condicion",
          fieldType = StringType),

        InputField(
          name = "laltitud",
          fieldType = BigDecimalType),

        InputField(
          name = "longitud",
          fieldType = BigDecimalType),

        InputField(
          name = "distancia",
          fieldType = IntType),
      )
    )
  }

  val Condicion: Argument[String] = Argument("condicion", StringType)
  val Latitud: Argument[BigDecimal] = Argument("latitud", BigDecimalType)
  val Longitud: Argument[BigDecimal] = Argument("longitud", BigDecimalType)
  val Distancia: Argument[Int] = Argument("distancia", IntType)


  val MutationType =
    ObjectType(
      "Mutation",
      fields[DataRepo, Unit](
        Field(
          name        ="addComercios",
          fieldType   = ComercioOutObject,
          arguments   = Condicion :: Latitud :: Longitud :: Distancia :: Nil,
          resolve     = c => c.ctx.gqlAddComercios(c.arg(Condicion),c.arg(Latitud) ,c.arg(Longitud),c.arg(Distancia))
        ),
      )
    )

  val SchemaDefinition: Schema[DataRepo, Unit] = Schema(QueryType,Some(MutationType))

Datarepo

def gqlAddComercios(condicion: String,latitud:BigDecimal,longitud:BigDecimal,distancia:Int=250):List[getComercio] = comercio(condicion,latitud,longitud,distancia,token).insertContent
Yann Simon
@yanns
What kind of help do you need? Your code is already looking good! :)
Michael Xavier
@michaaelsx_gitlab
I found the problem, addComercio returns a list, and i forgot add ListType(ComercioOutObject).
Yann Simon
@yanns
Great!
Lukasz S
@lukasz-swider

Hello,

I have the following field relation:

        Field("setups",
          fieldType = ListType(TransportSetup.toGraphType),
          arguments = fetchTransportSetupArgs.createGraphTypeArgs,
          resolve = ctx => setupFetcher.deferRelSeq(linkSetupByRouteId, ctx.value.getId)
        ),

I would like to pass the arguments of the field to my fetcher, i tried to make work deferred resolver but no luck so far

i can only pass ID
what am i doing wrong?
PsyfireX
@PsyfireX
If I try to convert my project to Scala 3, using the latest version of Sangria & Sangria-Circe (and no other sangria dependencies), should I probably be good to go? (reading through recent chats, it looks like progress is being made, but it's ambiguous how ready it is) @yanns
Yann Simon
@yanns
Sangria is not ready for scala 3 yet. There's still one big dependency that needs to be cross-compiled, with a lot of macros: https://github.com/sangria-graphql/sangria/projects/2
Any help welcome here ;)
Yann Simon
@yanns
@lukasz-swider A Fetcher defines the type of the ID. You can define it to what type you need.
If you need more control, you can go lower level, and use DeferredValueand DeferredResolver.
In my company, we are using both, and we combine them with DeferredResolver.fetchersWithFallback.
Lucas Della Bella
@lucasdellabella
Hi all, I wrote a query reducer but because the documentation is sparse im a bit confused about what the reduceAlternatives method is supposed to do / how its supposed to be implemented. Could anyone explain it in a sentence or two for me?
Lucas Della Bella
@lucasdellabella
@yanns maybe?
Yann Simon
@yanns

As I understand it: if you have n different values from n branches, this method is used to know what to do with those n values.
For example, in the MeasureComplexity:

  def reduceAlternatives(alternatives: Seq[Acc]) = alternatives.max

(https://github.com/sangria-graphql/sangria/blob/2a5c5e67f656dd2b84b6b8fc4d82b94f455046f5/modules/core/src/main/scala/sangria/execution/QueryReducer.scala#L75)

In TagCollector, we collect all tags:

  def reduceAlternatives(alternatives: Seq[Acc]) = alternatives.toVector.flatten

https://github.com/sangria-graphql/sangria/blob/2a5c5e67f656dd2b84b6b8fc4d82b94f455046f5/modules/core/src/main/scala/sangria/execution/QueryReducer.scala#L145

Does this help?
Christian Kjær
@Tehnix

I've been trying to dig into Sangria Fetchers (Data Loaders) and couldn't quite figure out if they go across requests or if they only act per-request. I found this PR mentioning that the caching is per-request, but haven't found anything to confirm if the batching/data loader part is as well 🤔 sangria-graphql/sangria#447

For example, imagine this scenario:

  • Request A: Get ID 2 via Fetcher
  • Request B: Get ID 2 via Fetcher

Would this result in 1 database calls (so, it works across requests) or 2 database calls (it's per-request)?

puneettandon
@puneettandon
Hi Can somebody help me fetching nested argument in graphql query .
query{
profession(id: "123456"){
resultList{
name
description
professionType
address
email
engineer(domain : "Software",skill: "Scala"){
department
domain
country
skills
}
doctor(speciality: "Ortho"){
hospital
speciality
yearsOfExperience
}
}
}
}
I have this query . And I want to fetch the arguments of sub-fields example - engineer field argument - domain
is it possible using sangria
as I want to query for professions under given with engineer skill as scala
puneettandon
@puneettandon
Please let me know if there is any way in sangria
Yann Simon
@yanns
@Tehnix they are per request. You can set up a cache if you want them across requests.
@puneettandon please try to format your post, it will help the readability.
Yes, it's possible to have arguments on any field.
Example:
        Field(
          "field_name",
          arguments = IncludeKeys :: ExcludeKeys :: Limit :: Offset :: SortArg :: Nil,
          resolve = ctx => {
            val includes = ctx.arg(IncludeKeys)
            val excludes = ctx.arg(ExcludeKeys)
            val limit = ctx.arg(Limit)
            val offset = ctx.arg(Offset)
richa002
@richa002
Hi ..I am new to sangaria graphql. I have a big list (about 500) of map having more than 300 key ,values in each map. I noticed while resolving , it is taking a lot of time approx 800-1200 ms . Can I improve the performance . Is there any way I can make the resolution of list parallelly. Any help highly appreciated.
Yann Simon
@yanns
Daan Debie
@DonDebonair
That is awesome!
PsyfireX
@PsyfireX
Awesome, I might give the Scala 3 branch a try in the next month!
My app is currently entirely Scala 2.13, so I'd have to carve out a chunk of time, but this was the last piece I was waiting for.
PsyfireX
@PsyfireX

I'm trying to make a HandledException and include a custom JSON response. That goes through the additionalFields: Map[String, ResultMarshaller#Node] = Map.empty, field, which Node appears to be an interface, perhaps supporting other libraries (ex: io.circe.Json).

Is there a way I can somehow pass Json directly into the HandledException.additionalFields ?

PsyfireX
@PsyfireX
Hah, I think I figured it out, I just needed the right implicit conversion.
        import _root_.sangria.marshalling.circe._
        val params = Map[String, ResultMarshaller#Node]("" -> io.circe.Json.obj())

        HandledException(
          log.traceId,
          params,
          addFieldsInError = true,
          addFieldsInExtensions = false,
        )
PsyfireX
@PsyfireX
That actually didn't work. I think I'm somewhere in the right ballpark though. If anyone has advice/suggestions, I'm interested.
PsyfireX
@PsyfireX
So, this actually works. A little messy, but I only need this code in one place.
        import _root_.sangria.marshalling.circe._

        val json: CirceResultMarshaller.Node = Json.obj(???)
        val params: Map[String, ResultMarshaller#Node] = Map[String, ResultMarshaller#Node](
          "error" -> json
        )

        HandledException(
          log.traceId,
          params,
          addFieldsInError = true,
          addFieldsInExtensions = false,
        )
Yann Simon
@yanns
You can also use implicit val resultTypeMarshaller = SimpleResultMarshallerForType[resultMarshaller.Node](resultMarshaller), and add your json like value.convertMarshaled[resultMarshaller.Node]
Yann Simon
@yanns
Anyone has tried the release for scala 3?
PsyfireX
@PsyfireX
(not yet, although I did just upgrade a bunch of dependencies including Sangria)
PsyfireX
@PsyfireX
I may actually be trying the Scala 3 release very, very soon. I'm trying to upgrade my entire project to Scala 3, but have a massive number of errors to fix before I get to the GraphQL layer. I'll report back if/when I run into anything.
Yann Simon
@yanns
great to hear!
PsyfireX
@PsyfireX
Update: I migrated everything in my app to Scala 3, except the GraphQL layer which I just started.
The first minor obstacle is circe-optics appears to only be available in Scala 2, which it's transitive dependencies are causing conflicts. The fastest workaround will probably be dropping circe-optics, since I only have a few places which use it, although I'm also asking for advice on the circe gitter.
PsyfireX
@PsyfireX
@yanns I haven't yet dove deep into this exception yet, but it looks like I'm running into issues with deriveObjectType and macros.
    implicit val _ot: ObjectType[Ctx, UpdatePostGql] =
      deriveObjectType[Ctx, UpdatePostGql](
        ObjectTypeName("UpdatePost")
      )
Exception occurred while executing macro expansion.
scala.MatchError: OrType(AndType(TypeRef(TermRef(TermRef(TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object ai),object tagr),object graphql),object tagr),object schema),object types),class BodyInputGql),AppliedType(TypeRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class sangria)),object util),tag),type Tagged),List(TypeRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class sangria)),object marshalling),FromInput),InputObjectResult)))),TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Null)) (of class dotty.tools.dotc.core.Types$CachedOrType)
    at dotty.tools.dotc.transform.TypeUtils$.companionRef(TypeUtils.scala:91)
    at dotty.tools.dotc.typer.Synthesizer.companionPath(Synthesizer.scala:252)
    at dotty.tools.dotc.typer.Synthesizer.productMirror(Synthesizer.scala:311)
    at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$6$$anonfun$1$$anonfun$1$$anonfun$1(Synthesizer.scala:396)
    at dotty.tools.dotc.typer.Synthesizer.makeMirror(Synthesizer.scala:388)
    at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$6$$anonfun$1(Synthesizer.scala:396)
    at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$8$$anonfun$1(Synthesizer.scala:413)
    at dotty.tools.dotc.typer.Synthesizer.recur$1(Synthesizer.scala:556)
    at dotty.tools.dotc.typer.Synthesizer.tryAll(Synthesizer.scala:561)
    at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:857)
    at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:785)
    at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:117)
    at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3451)
    at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3487)
    at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3563)
    at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3761)
    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3995)
    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
    at dotty.tools.dotc.typer.Typer.readapt$1(Typer.scala:3340)
    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3982)
    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
    at dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1053)
    at dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:785)
    at dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:117)
    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1173)
    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.rank$1(Implicits.scala:1272)
    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1442)
    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1470)
    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1503)
    at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:997)
    at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:785)
    at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:117)
    at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:851)
    at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:785)
    at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:117)
    at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3451)
    at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3487)
    at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3563)
    at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3761)
    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3995)
    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
    at dotty.tools.dotc.typer.Typer.readapt$1(Typer.scala:3340)
    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3982)
    at dotty.tools.dot
PsyfireX
@PsyfireX
It appears this type of error mostly applies to classes using @GraphQLExclude and @GraphQLField annotations.
  case class UpdatePostGql(
    @GraphQLExclude
    ctx: Ctx,
    @GraphQLExclude
    id: PostId,
  ) {
    @GraphQLField
    def publishDraft(): Future[PostGql] = ???

    @GraphQLField
    def body(body: BodyInputGql): Future[PostGql] = ???

    @GraphQLField
    def publishVersion(index: Int): Future[PostGql] = ???
  }
Yann Simon
@yanns
@PsyfireX very good feedback! Could you open an issue for this?
It seems that you already have found a way to reproduce it. It should help fixing the issue.
PsyfireX
@PsyfireX
Sure, I was about ready to head to bed - so I'll do that when I wake up. I'll also try to distill it into a piece of code that doesn't rely on my project as well, as to make it more reproducable.
PsyfireX
@PsyfireX
I finally was able to make it reproducible without depending on my project:
sangria-graphql/sangria#905
Yann Simon
@yanns
Thanks a lot!
PsyfireX
@PsyfireX

@yanns No problem, a much bigger thank you for maintaining and supporting Sangria.

Do you have any ideas about when you expect the bug to be fixed? I'm just trying to determine whether or not to go through the effort of switching from derived to manual, since the one final place this bug appears is the very top-level query type containing all of the other query types.

PsyfireX
@PsyfireX
(macros are over-my-head, otherwise I'd look into it)
PsyfireX
@PsyfireX
Disregard my above comment, I see you've already started looking at it! (of course that's not an estimate, but perhaps worth waiting a short while instead of doing a rewrite).