Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Binh Nguyen
@ngbinh
awesome!
Gryum
@Gryum

hi everybody! Could you please help me. I have graphql query and schema. What is the best way to analyze query and retrieve all requested fileds with proper type? For example in recursive structure:

sealed trait GraphQlFieldType {
val typeName: String
}

final case class GraphQlField(name: String, fieldType: GraphQlFieldType, isArray: Boolean = false)

final case class GraphQlFieldTypeDataClass(typeName: String,
fields: List[GraphQlField]) extends GraphQlFieldType

rolandjohann
@rolandjohann
Hi all,
how do you handle transactions for subscriptions? For normal grahql requests I use a single transaction for queries and mutations. This transaction is part of the context. Using this same mechanism for subscriptions is insane. Do you create a separate SubscriptionContext without transactions or do you guys have another suggestion?
rolandjohann
@rolandjohann
Didn't consider that the types won't match anymore when I use a different context type. So the context should get an optional transaction. Do you see a more elegant solution? Since getting a transaction as option at batch requests is somehow bad: there the transaction is mandatory
rolandjohann
@rolandjohann
Ok, further question: Anyone has experience with sangria subscriptions over websocket and frontend clients like apollo/graphql-ws? Just realized that they implement an additional protocol for session handling between websockets and gql. Already found the relevant issues at github pointing towards apollo server in front of sangria. This means that the session related stuff will be handled externally by manipulating the stream elements emitted by sangria. So the implementation in scala would be to implement the session handling and wrap the sangria stream, so we manipulate the JsValues? This seems kind of hacky... Is there a way to provide a different marshaller for sangria Actions?
rolandjohann
@rolandjohann
Dug into the code and session protocol. Wrapping the sangria stream will be the way to go. Any feedback is highly appreciated.
Tam-bhall
@Tam-bhall
Hi All,
I have a use case where I accept multiple ids in a fetcher and want to return partial results in case fetcher couldn't give data for some of the IDs. For ex:
Schema : Car { id: int}
And let's say my input has 3 ids: 000,111,222 and out of those 2 were not found
I want response something like(basically to let the user know what happened with 2 ids which are not in data result):
"data": { "getCar:[ { "car": { “id”: “111” } } ] }, "errors": [ { "message": “Couldn’t find data for car” "code":"404" “fields” : ”000,222” } ] }
Is something like this possible in Sangria? Any help is greatly appreciated
2 replies
Performant Data
@performantdata
Anyone know what UnmodifiedType is for? I don't see it used in Sangria code.
Akhil Bhandaru
@avbhandaru

Suppose I have the following schema:

lazy val ParentType = ObjectType(
  "Parent",
    collect[...](
      Public(
        Field("child", ChildType,
          resolve = _.value.child
        )
      )
  )
)

lazy val ChildType = ObjectType(
  "Child",
    collect[...](
      Public(
        Field("something", StringType,
          resolve = ...
        )
      )
  )
)

Is there a way to reference a field in the parent value/type within the resolve method of the ChildType's "something" resolve field.

Grzegorzkociole
@Grzegorzkociole
Justin Reeves
@clutch-justin

I'm trying to do some custom instrumentation in New Relic similar to their recent graphql-java instrumentation:
https://github.com/newrelic/newrelic-java-agent/blob/5a035c11d3b0226655468d780c38342a60e790a7/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLSpanUtil.java#L39

What would be the equivalent of graphql-java's graphql.execution.ExecutionStrategyParameters? Can I derive it from sangria.ast.Document
https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/ExecutionStrategyParameters.java

Yann Simon
@yanns
Have you looked at https://github.com/sangria-graphql/sangria-slowlog#opentracing-support and see if it's similar to what you need?
Yann Simon
@yanns
Yann Simon
@yanns
Daniel Koves
@danielkoves_twitter
Hi, is there a way to filter on relationship fields in Sangria, i.e. something like described here: https://stackoverflow.com/questions/56622494/query-by-relationship-for-graphql ?
Yann Simon
@yanns
Sangria is totally agnostic about how you do that. For example, we expose predicates that we implement ourselves.
Daan Debie
@DandyDev
Hey folks! After having worked with Sangria in a previous project at another company, I'm now looking to build a GraphQL API at the startup I'm now working for. Naturally, Sangria is an enticing option.
The only thing that is sort of holding me back: Scala 3 is out. It's shiney, new and much better than Scala 2.13. I saw that Sangria is not released for Scala 3 yet, correct?
Is there a timeline for this?
jgillich
@jgillich:matrix.org
[m]
Trying to update sangria to 3.0 and I get a NoClassDefFoundError: sangria/parser/DeliveryScheme https://gist.github.com/jgillich/3e8d90dde7526d47a5f5fe496aae9889
Source is very simple: https://github.com/graphql-crystal/benchmarks/tree/main/sangria
Any ideas? Wondering if it's related to sangria-akka-http-circe
Samuel
@DevFlex
Are there any examples using a Projector to convert the fields into a BSON document to actually use in the projection of the mongo db query?
Yann Simon
@yanns
@DandyDev for scala 3, 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
Yann Simon
@yanns
@jgillich:matrix.org I've tried to update the sangria library to 3.0.0 on your project and it's working for me. Can you maybe open an issue with more details and how to reproduce it?
@DevFlex we're using projector but we are using the graphql field names to know which fields to fetch from mongo. I'm not sure what you are trying to achieve. Can you explain further?
Daan Debie
@DandyDev
Thanks for the answer @yanns
Michael Xavier
@michaaelsx_gitlab
Hi, its possible to insert data to database if ID no exist.
Yann Simon
@yanns
@michaaelsx_gitlab your question is not really related to GraphQL and sangria. I'd advise you to ask this question to the community of your database vendor.
Michael Xavier
@michaaelsx_gitlab
@yanns Thanks for the reply
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)