Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Yann Simon
@yanns
Please welcome a new release candidate: https://github.com/sangria-graphql/sangria/releases/tag/v3.0.0-RC2. Feedback welcome!
Yann Simon
@yanns
Ups, I spoke too fast - the artifact is not published on maven central yet.
Ishan Shah
@nullptr7
Is it possible to have InputObjectType as traits. I understand that InputObjectType allows only scala case class But any suggestions on how can be achieved?
Yann Simon
@yanns
InputObjectType is used to represent a GraphQL type that can be used as an input, for example for an argument.
People usually use that with a scala case class as it's convenient. But you can use it with a trait, that you have to instantiate yourself at some point.
But if you are using a trait, we may have different implementations in scala. In that case, it may be better to expose a GraphQL interface and some concrete types of it.
Performant Data
@performantdata
Do we know why DeliveryScheme exists? Seems like Try could have been used instead.
Yann Simon
@yanns
In AlternativeDeliverySchemes, you can find different implementation of it. I personally have never changed it. So I don't know the value of it.
rney-lookout
@rney-lookout
Question: Is there an implementation of the Schema Reporting Protocol for Sangria? We're starting to try and keep a schema registry and would like to have publishing automated as we deploy new versions.
Abhishek Gupta
@abhigp27
Question: Is there a way to remove the path and location values from Exception, Only interested in error message and extentions values. A little further, is it possible to overwrite the whole structure and replace with only errorCode, Description and a custom message?
2 replies
Yann Simon
@yanns
Hi everyone, I made a online talk about how we use sangria for a platform with intense GraphQL usage. Maybe you'll be interested: https://yanns.github.io/blog/2021/10/28/graphql-conf/
Longyang Zhang
@zhanglongyang
Hi everyone, I'm doing some spike around Sangria stream-based subscriptions and from the doc, looks like multiple top-level fields are supported. However, checking graphql spec, Subscription operations must have exactly one root field. Also some graphql clients, like GraphiQL, don't support that either. Just wondering is Sangria doc not up-to-date? OR it does not follow the spec? Thanks
Yann Simon
@yanns
Subscriptions in sangria have been implemented when the spec was still in discussion / beta. It's possible that it's not following the spec fully.
Please welcome a new RC release: https://github.com/sangria-graphql/sangria/releases/tag/v3.0.0-RC7
The modularization is in progress: the AST and the parser are now in separated modules.
Thanks @performantdata for this!
We add deprecations in the v2 releases to make the upgrading path easier. Make sure to fix those deprecations before upgrading.
Feedback welcome!
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?