My server now:
1) SUCCESS: starts, and successfully returns the Schema (introspection).
2) SUCCESS: Processes input, runs my backend code, and then...
3) FAIL: Fails to generate the output on several endpoints, using various ObjectTypes.
"class scala.concurrent.impl.Promise$DefaultPromise cannot be cast to class ai.tagr.graphql.tagr.schema.types.UserGql (scala.concurrent.impl.Promise$DefaultPromise and ai.tagr.graphql.tagr.schema.types.UserGql are in unnamed module of loader 'app')
java.lang.ClassCastException: class scala.concurrent.impl.Promise$DefaultPromise cannot be cast to class ai.tagr.graphql.tagr.schema.types.UserGql (scala.concurrent.impl.Promise$DefaultPromise and ai.tagr.graphql.tagr.schema.types.UserGql are in unnamed module of loader 'app')
ai.tagr.graphql.tagr.schema.types.UserGql$.$init$$$anonfun$1$$anonfun$13(UserGql.scala:59)
sangria.execution.Resolver.resolveField(Resolver.scala:1513)
sangria.execution.Resolver.collectActionsPar$$anonfun$1(Resolver.scala:713)
scala.collection.IterableOnceOps.foldLeft(IterableOnce.scala:646)
scala.collection.IterableOnceOps.foldLeft$(IterableOnce.scala:642)
scala.collection.AbstractIterable.foldLeft(Iterable.scala:926)
sangria.execution.Resolver.collectActionsPar(Resolver.scala:722)
sangria.execution.Resolver.resolveValue(Resolver.scala:1331)
sangria.execution.Resolver.resolveStandardFieldResolutionSeq(Resolver.scala:441)
sangria.execution.Resolver.resolveSingleFieldSeq(Resolver.scala:400)
sangria.execution.Resolver.resolveSeq$$anonfun$1$$anonfun$1(Resolver.scala:356)
scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:834)"
I'm not really sure what this error means. However, in this example, UserGql is a fairly basic return/output ObjectType
and I get the same error on my other endpoints.
Issue 905 and 906 look very different. 905 is an implicit resolution issue or conflict with io.circe
, which causes compiler errors. 906 appears to be Sangria getting confused about how to render a Future[???]
even with simple types like String
(Although as someone not familiar with the code, I guess it's technically possible they could be related, just seems unlikely)
Future[T]
to just return T
instead. I don't know what the performance difference is, but I'm still months away from dealing with any notable traffic. Once 905 and 906 are fixed, I'll remove my workarounds. Anyway, I appear to have a working GraphQL server in Scala 3, and will use the Scala 3 branch as "master." I'll report any other bugs I run into if any.
io.circe
but they were easy to workaround and not caused by Sangria.
Hi everybody!
I am facing a "problem" with Sangria (I'm new to it AND to Scala so maybe my problem is due to my lack of knowledge !).
If someone can help me... i'm kinda despesperated :)
So here it is:
DeferredValue(Fetchers.fetcherA.deferOpt(ctx.value.id))
.map(entitiesFromA => {
DeferredValue(
Fetchers.fetcherB.deferSeqOpt(entitiesFromA)
).map {
case Nil => None
case entitiesB =>
Some(
Connection.connectionFromSeq(
entitiesB,
args,
SliceInfo(sliceStart = offet, size = offset + entitesB.size)
)
)
}
Of course, it doesn't work. Compiler needs a Option[Connection[EntityB]] and it gets a DeferredValue[Nothing, Option[Connection[EntityB]]].
I think my problem comes from the nested fetcher calls + Connection stuff. I don't really know how to do.
If someone has an idea, do not hesitate to tell me.
Thank you!
From what I understand:
I'm not very used to use Fetchers, but I think that fetcherA could be a Relation[..., ID]
and used like:
Fetchers.fetcherB.deferRelSeq(Fetchers.fetcherA, ctx.value.id)
Hello,
I would like to upgrade a project to Sangria 3, and this project uses sangria-relay
module.
By looking at https://github.com/sangria-graphql/sangria-relay, I can see that the project is regularly updated (e.g. scala-steward updates).
However, I don't see any new release in Maven or GitHub. I am missing something ?
Thanks in advance :)
Looking for some direction. Learning and haven't seen examples.
I'm prototyping a GraphQL service for our platform data.
gRPC to Platform Services returngin Protobuf -> mapping to case classes -> serving over GraphQL
I tried deriveObjectType
directly with the Protobuf and that had its own challenges.
So now I'm trying to mapping to case classes and I have a number of case classes with a bunch of Option fields
Like
case class Policy(
policyId: UUID,
cancelEffectiveTime: Option[Instant] = None,
cancelledBy: Option[PolicyAction] = None,
carrier: Option[Carrier] = None,
renewal: Option[Renewal] = None,
underwritingCriteria: Option[UnderwritingCriteria] = None
)
I'm wondering the best way to define these for the schema
I've done
private val policyType = deriveObjectType[PlatformRepo, Policy]()
But get errors like
Can't find suitable GraphQL output type for Option[zego.controlpanel.domain.Renewal]. If you have defined it already, please consider making it implicit and ensure that it's available in the scope.
Which I'm then trying
private val policyType = deriveObjectType[PlatformRepo, Policy](
ReplaceField(
"carrier",
Field(
"carrier",
OptionType(carrierType),
resolve = ctx => ctx.value.carrier
)
),
.
.
.
)
Is this the proper/best way to define Option(s) the schema? It works.
I'm going to have a number of case classes with Option fields and want to find the most efficient way of mapping them.
deriveObjectType[PlatformRepo, Policy]()
does not know how to expose your domain classes (like Carrier
, PolicyAction
...) to the GraphQL schema.
Fetcher
and Deferred
's. Is there something similar to what Future
has with Await.result()
for getting a value out of a Deferred
? I'm not talking about DeferredValue().map()
, because that still wraps the transformed results with a Deferred
. More like Option().get
, which gives you the value.
DeferredResolver
returns Future
that you can await. Does this help?
DeferredResolver
from DeferredResolver.fetchers()
. But it looks like the .resolve()
needs a queryState
, which is an Any
, but is converted to a FetcherCache
. I can't figure out where to get that cache from. From what I can tell, FetcherConfig
can give an empty cache, but not one that has been populated by previous fetches.
sangria-federated
project is getting some more frequent updates. Is the community looking at achieving Federation 2.x
level support so it can work with the Apollo Router? Was concern moving to Caliban was required for us to start supporting the router.
@yanns, no, it's not for testing. This is for production.
My project is for an Academic Research website (think Google Scholar). At the core, we have Paper
's and Author
's. A Paper
can have many Author
's, and an Author
can have many Paper
's.
In one place, I'm trying to return a Connection[Author]
for a Paper
. To do this, I need to:
0) Look up a Paper
from a Fetcher
(sets value of context.value
)
1) Fetch the author IDs for the Paper
(returns a Future
)
2) Take a slice of those author IDs to create a page of IDs
3) Fetch the Author
's with those IDs from a Fetcher
(returns a Deferred
)
4) Return a Connection[Author]
(or Future[*]
, Deferred[*]
...don't care since sangria can handle either)
So I have a mix of Future
's and Deferred
's. Since my team has experience in Future
's, I was trying to get the code to rely more on those than on Deferred
(which would be unique to this part of the code). Ideally, I'd like to be able to reuse the Fetcher
's such that I can get records as intermediaries, and still have them cache (think CoAuthors
using a Paper
as an edge in the graph).
Future
. I keep the sangria code very thin, only calling other implementations.Deferred
as Future
. Deferred
is a marker for a value that should be resolved by a Fetcher
or DeferredResolver
.Deferred
does not do anything unless it's resolved.Future
triggers the computation of the value (with side-effect). So it's quite different.
deriveEnumType
seems to support ADT: https://github.com/sangria-graphql/sangria/blob/main/modules/derivation/src/test/scala/sangria/macros/derive/DeriveEnumTypeMacroSpec.scala but I'm not sure if it's what you are looking for.