Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Justin Reeves
@justinallenreeves

Trying some tests, able to make PartialValue work okay

val Food: Field[Context, Val] = {
    Field(
      name = “Food",
      fieldType = OptionType(StringType),
      resolve = _ => PartialValue(Some("Waffles"), Vector(new Exception("Pancakes"))
    )
  }

This works as expected

But PartialFutureValue won’t compile

val Food: Field[Context, Val] = {
    Field(
      name = “Food",
      fieldType = OptionType(StringType),
      resolve = _ => PartialFutureValue(Future.successful(PartialValue(Some("Waffles"), Vector(new Exception("Pancakes”)))))
    )
  }

There’s type mismatch, it’s looking for sangria.schema.Action[Any,Option[String]]

Yann Simon
@yanns
Maybe the type inference is not working. The guideline you send contains types to help the inference: PartialValue[Unit, Option[String]]
abhishekvaidprophecy
@abhishekvaidprophecy
In my production setup I want to avoid people from introspecting my GraphQL definitions using Apollo plugin. Is there a way to do this with Sangria ?
Justin Reeves
@justinallenreeves
@abhishekvaidprophecy you can check if the incoming request is introspection on the Context[Ctx, Val]
and just refuse the request by whatever mechanism (like throw an exception or returns a Forbidden)
Nick Isaacs
@nicky-isaacs
Hi folks. I have a question about sangria marshalling. I am playing around with attempting to make a marshaller which marshals results to Thrift, but one sticking point is that it appears that ResultMarshaller (https://github.com/sangria-graphql/sangria-marshalling-api/blob/master/src/main/scala/sangria/marshalling/ResultMarshaller.scala) does not hint at which arm of a union is being marshalled, thus I cannot seem to figure out how to render a more refined type other than key/value pairs. Does anyone have any ideas for how I could attempt to solve for this?
1 reply
Mads Saustrup Fox
@MadsSaustrupFox
Hey, wanting to implement pagination in the plural GQL queries. Does anybody know if it's already part of the Sangria lib or can anybody point me to a resource about how to implement it.
Have read this:
https://graphql.org/learn/pagination/
and following their advice i would like to implement cursor based pagination
Justin Reeves
@justinallenreeves
@MadsSaustrupFox Sangria doesn’t have anything to implement because it’s not responsible for subsetting or sorting your data, only resolving it. I use limit/offset arguments for pagination. A cursor would work similarly.
1 reply
Basically, same as you would if it was a simple REST service
Alexej Haak
@Daxten
Hidiho guys, just found out that I can't use Interfaces/Unions as InputTypes in graphQl (buuuuh!), is there a way to create sth like ScalarAliases for InputTypes?
Problem I want to solve is: I have a @GraphQLField which takes a sealed trait as a Parameter. Now I want to create an InputObject which has every implementation of the sealed trait as a property and then create an alias which fails if not exactly one property is Some
to somehow emulate a Union/Interface
I'm also not sure if I can write the mapping of InputFields to Scala class by hand somehow? There seems to be a lot of macro / reflection magic involved here?
Alexej Haak
@Daxten
Okay this is cool imo, I added implicit conversions for SumEmulationOfUnionType => UnionType and vice versa and all the macros etc. work with the implicit conversions
At least I think... it compiles so far lets say :P
Alexej Haak
@Daxten
meh no that doesn't work
so anyway to create an Input type by mapping an already existing InputType? Or by doing the deserialization myself (e.g. MyClass(arg("a"), arg("b")))
Alexej Haak
@Daxten
Okay now I understand one thing more: deriveInputObject actually derives 2 things, the InputObject and FromInput
I thought the FromInput stuff is happening "somehow" in InputObject... so with these 2 combined I can write my own deserialization, nice!
Christian Kjær
@Tehnix
Does anyone have good examples of setting up UnionTypes? Been running into UndefinedConcreteTypeError: Can't find appropriate subtype of a union type and for the love of god I can't find a fix for it :/
Christian Kjær
@Tehnix
...nevermind, apparently I was returning it in a effect which we'd normally do, but it fail until runtime with a very unhelpful error message 😅
Daan Debie
@DandyDev
Hey all! I have a question to which I couldn't find the answer: is Sangria compatible with Scala 3 yet? Is it on the way?
Yann Simon
@yanns
@DandyDev there were no efforts into porting Sangria to Scala 3 yet. If you are motivated, you're welcome to help. Development efforts are coordinated on #sangria-dev.
Shohei Shimomura
@sh0hei
@yanns @DandyDev I plan to make sangria compatible with scala3 :thumbsup: Currently working :muscle: Welcome your help at any time.
1 reply
Yann Simon
@yanns

@yanns @DandyDev I plan to make sangria compatible with scala3 :thumbsup: Currently working :muscle: Welcome your help at any time.

🤩

alex-gaiduchok
@alex-gaiduchok

hey guys, need your advice:
switched sangria to 2.1.0
PR looks like this

    "org.sangria-graphql" %% "sangria" % "1.4.2" =>  "2.1.0",
    "org.sangria-graphql" %% "sangria-relay" % "1.4.2" =>  "2.1.0", 
    "org.sangria-graphql" %% "sangria-circe" % "1.2.1" =>  "1.3.1",
    "org.sangria-graphql" %% "sangria-slowlog" % "0.1.8" =>  "2.0.1",

nothing else was changed.

And faced a memory leak 6 hours after the update (maybe related to traffic).

Maybe someone also faced mem leak at sangria 2.10 ?

alex-gaiduchok
@alex-gaiduchok
platform is graalvm 20
Yann Simon
@yanns
running with this version since months with high traffic, and we have no memory leak about it.
But the leak could also come from how you instantiate your schema...
The better to find it is to check the memory, for example with java mission control. Altough I don't know which tools will work with graalvm.
alex-gaiduchok
@alex-gaiduchok
sure, I will try to look at this problem with the profiler, just want to be sure that nobody faced/solved this problem, before dive deeper in debugging
sjuyal12
@sjuyal12
Hey! I want to write a graphql mutation using sangria which returns a List. However, currently I only can figure out writing mutations which return an object not a list of objects. Like :- val MutationType: ObjectType[GraphQLContext, Unit] = ObjectType("Mutation", fields[GraphQLContext, Unit](
And then val schema: Schema[GraphQLContext, Unit] = Schema(QueryType, Some(MutationType))
Yann Simon
@yanns
Your mutation could contain a Field("results", ListType(ObjectType).... Does it work?
Witold Soczek
@v-tec2706

Hi, I have a question about deferred resolution. Is there a way to run multiple deferred resolutions one by one? What I want to achieve in resolver function is:

for {
   idsA <- deferredFetchA
   idsB <- deferredFetchB
  selectedItems <- do sth with idsA and idsB
} yield anotherDeferredFetch(selectedItems)

I was trying to play with DeferredValue(...) but with no success

Yann Simon
@yanns
See https://sangria-graphql.github.io/learn/#deferred-value-resolution
In your schema, use your own class that extends Deferred.
In your DeferredResolver, you have access to all your accumulated Deferred instances. Based on this input, you can choose how to resolve them. And this can be one by one if you want to.
Yann Simon
@yanns
If you use Fetcher, you might be interested in this change that allows setting the max concurrency: https://github.com/sangria-graphql/sangria/pull/454/files
This PR would need help (rebase on last version I guess) so that it could be integrated.
Witold Soczek
@v-tec2706
thank you @yanns! I'll try that
Justin Reeves
@justinallenreeves

Currently getting an error when returning a large page of results Fetcher has not resolved non-optional ID ‘<SOME_ID>’
I’ve looked at the ids thrown by the error and found the objects/entities they refer to (it’s a nested object inside the object being queried) and they exist
I can do a more narrow query that filters for that specific object and get page with 1 result.
It so far only seems to blow up when I have to many.

Perhaps this is an issue with a the Future for the Field being queried is resolving before the defered resolver finishes?

Yann Simon
@yanns
@justinallenreeves is it a new issue? In which version do you observe that?
Justin Reeves
@justinallenreeves
We’re on 2.0.0 but I’m not sure it’s a bug with Sangria.
I’ve been playing with page sizes all morning trying to reproduce but it looks like it’s related to the data.
I neglected to included the exception, it’s a sangria.execution.deferred.AbsentDeferredValueError
Alexej Haak
@Daxten
FetcherBasedDeferredResolver.scala:245 there is no way to give Fetchers a name or sth right now if understand correctly... I have like 10 fetchers in my project and if one throws that error it's pretty hard to debug which one
Since the thread trampolining removes the stacktrace
Yann Simon
@yanns
Please feel free to add issues with as much info as possible. And we can also help you to make your first PR if you like ;)
Greg Fisher
@gnfisher
I am running into an issue where Sangria is not generating a type as I would like. I've got a Validated[A] type with a GraphQLOutputTypeLookup[Validated[A]] defined thusly:
  implicit def validatedType[A](
      implicit lookup: GraphQLOutputTypeLookup[A]
  ): GraphQLOutputTypeLookup[Validated[A]] =
    new GraphQLOutputTypeLookup[Validated[A]] {
      def graphqlType: OutputType[Validated[A]] =
        ObjectType(
          s"Validated${lookup.graphqlType.namedType.name}",
          fields[Ctx, Validated[A]](
            Field("value", lookup.graphqlType, resolve = _.value.value),
            Field(
              "fatal",
              ListType(FatalType),
              resolve = _.value.status.fatal
            ),
            Field(
              "warning",
              ListType(WarningType),
              resolve = _.value.status.warning
            )
          )
        )
    }
The issue is having both a Validated[String] and Validated[Option[String]]. If only one or the other is present, it works as expected ( in elm I get a Maybe String in the generated graphql object). But if both are present, only one is generated. So in my case, only a ValidatedString type exists, and its not a Maybe String in elm land.
Validated looks like this:
case class Validated[A](value: A, status: Status) {
  def map[B](f: A => B): Validated[B] =
    copy(value = f(value))
}
I think it has something to do with how the type name is generated with this line: s"Validated${lookup.graphqlType.namedType.name}",