Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Daave
@Yomanz
I noticed that v2.0.0 was out now but there is no documentation for it.
I'm midway through building my API and interfaces were changed in sangria 2 and as there is no documentation I'm unsure how to use them
If anyone has any pointers on how to extend/use interfaces or has a github they can share it would be appreciated
Paul Daniels
@paulpdaniels
@will08rien for our sangria-based services we rolled our own federation internally because it required changes to the marshaller, for anything in the ZIO realm we use caliban though.
Will O'Brien
@will08rien
Thanks @paulpdaniels!
joshhidley
@joshhidley
@yanns We got streaming working , but only if we expose our query as a subscription. Has anyone had success using a streaming execution scheme, but with a normal query? This documentation suggests it's possible: https://sangria-graphql.org/learn/#alternative-execution-scheme
Yann Simon
@yanns
I've only used it with subscriptions. So I cannot say more.
joshhidley
@joshhidley

I've only used it with subscriptions. So I cannot say more.

OK thanks. Still looking for help in case anyone else has done this.

Justin Reeves
@justinallenreeves
We have some objects nested together and are trying to figure out defaults for Seq[T] in mutations where the Argument's type is the product of the deriveInputObjectType macro on the top type
It seems we have to wrap it in Option and OptionType but that means a Option[Seq[T]] which is kind of a pain
Is there a better way that results in not having our API consumers pass empty arrays?
Justin Reeves
@justinallenreeves

What do you do in Sangria if you want to provide some kind of validation like an argument must match a pattern or condition?
like if I'm

mutation updateFooStatus($fooId: FooId!, $status: String!) {
   updateFooStatus(fooId: $fooId, status: $status)
}

and status must be either "An Apple", "A Banana", "A Carrot"?
I can't make them enums because I need the the API to return "An Apple"

a contrived example
Justin Reeves
@justinallenreeves
I think I found the answer in ScalaAlias[Fruit, String]
Justin Reeves
@justinallenreeves
It worked!
Made a new violation for it, so it looks like a string, acts like a string, but behaves like the sealed trait + case objects it is underneath the hood
Parth Desai
@parth-code
Hi! I'm starting out with Sangria again. I'm not quite an advanced Scala developer, and I find the documentation quite vague and difficult to follow. Are there links to tutorials or examples which I can use to understand this better?
kamisama-rney
@kamisama-rney
@here Hi, I'm starting on my first production use of Sangria to create my company's first GraphQL API. Looking at the API documentation it appears there are many ways to describe a schema. What approaches are people using? The DSL, Annotations, Introspection???
My API design does support a large number of parameterized fields.
Erik
@erikdstock
Hi @parth-code and @kamisama-rney - I'm in a similar situation to you two, actually picking up a sangria schema that has been mostly frozen for the past 2 years due to these issues. Maybe we will figure things out together.
Parth Desai
@parth-code
Sounds like a plan @erikdstock
vaIgarashi
@vaIgarashi

Type name 'X' is used for several conflicting GraphQL ObjectTypes based on different classes.

Is there any options to disable this check?

Mesut Yiğit
@mesutyigit
Is there anyone resolve this issue. This throw evere recompile the project.
[warn] [E-1] an unexpected type representation reached the compiler backend while compiling GraphQLTypes.scala: (marginChar: Char): String <and> (): String. If possible, please file a bug on https://github.com/scala/bug/issues. [error] [E-1] Error while emitting GraphQLTypes.scala [error] (marginChar: Char): String <and> (): String (of class scala.reflect.internal.Types$OverloadedType) [info] Legend: Ln = line n, Cn = column n, En = error n [error] (Compile / compileIncremental) Compilation failed [error] Total time: 3 s, completed Jul 14, 2020, 1:00:34 PM
Peter Gerhard
@peter-gerhard

:wave: Hi, Anyone knows how to properly embed objects in graphQL schema? I did not find anything in the documentation:
I have the following use-case:

case class Outer(a: String, embedded: Embedded)
case class Embedded(c: String, d: String)

What I would like to achieve is that the fields c and d are accessible in the api directly from the outer object.

The only way I currently see to achieve this is to manually add these fields in the OuterType definition:

implicit val EmbeddedType = deriveObjectType[MyCtx, Embedded]()
implicit val OuterType = deriveObjectType[MyCtx, Outer](
  AddFields(
    Field("c", StringType, resolve = _.embedded.c),
    Field("d", StringType, resolve = _.embedded.d)))

The problem here is that this is not forward compatible if we add new fields to Embedded in the future.

kamisama-rney
@kamisama-rney

@mesutyigit which version of Scala are you using? I just came up against this using Scala 2.13.3 and ended up converting my schema definitions to explicit definitions via ObjectType

 ObjectType(
      "Application",
      () =>
        fields[MasterRepo[F], Application](
          Field(

to get my code compiling again. We were fine until I started adding in the documentation via @GraphQLDescription()

Mesut Yiğit
@mesutyigit
I see this error both of scala 2.13.2 and 2.13.3
kamisama-rney
@kamisama-rney
That's expected given those are only 1 minor release apart. I was curious if this was also experienced in 2.12.10 or other "current" versions of Scala 2.12. I didn't rollback to 2.12 since I have a bunch of Java conversions in my schema case classes since I'm ingesting data from a common Avro library and the package for JavaConversions changed between 2.12 and 2.13
Erik
@erikdstock
how do folks generally organize their schema files? Especially given that our are all vals they don't lend themselves to a package structure
The only example I can find is https://github.com/sangria-graphql/sangria-relay-playground/blob/master/app/models/SchemaDefinition.scala - which for a very small schema is a very large file
kamisama-rney
@kamisama-rney

@erikdstock I'm in the process of designing a new schema right now that's quite large. I've created a model package with several sub-packages for each collection of Type objects. Since we're using http4s, functional-streams for scala, and cats.effect for our code we've implemented everything as object with the apply method constructing the type

object ApplicationType {

  def apply[F[_]: Effect]: ObjectType[MasterRepo[F], Application] = {

    ObjectType(
      "Application",
      () =>
        fields[MasterRepo[F], Application](
          Field(
            "appId",
            StringType,
            resolve = _.value.appId
           )
        )
    )
}

Most of the types are in their own files if they're only nested 1 level from the root schema item Application. For items I'm nesting down 2-3 levels and aren't shared with other types I've included them as implicit types at the top of the apply method.

Hope that helps

Erik
@erikdstock
Interesting, thanks.
kamisama-rney
@kamisama-rney
We also started with a separate schema JAR and used deriveObjectType[MasterRepo[F], Application] but once I started adding documentation to the classes with the Attributes a bug in Scala 2.13 was exposed in compile time reflection. Thus I went back to the old ObjectType approach.
Erik
@erikdstock
Alright, i've been wrestling with this a bit today and have an example here that works, but i'm curious on others' thoughts. In this case we have a Money case class that has been created specifically to define presentational logic for our money numbers, and the GraphQL MoneyType exists in the companion object. In other cases, we might have for example an object User might include a UserType even though the user model exists outside our graphql package. Does this make sense?
https://gist.github.com/erikdstock/09dc318dfea84f5f4f307fc2a487aecd
Apologies that it's a bit verbose, it's one of our simpler bits of legacy code - you can mostly ignore the case class implementation to be honest.
Erik
@erikdstock
Minimal Example:
case class Foo(bar: Bar)

object Foo {
  lazy val FooType = deriveObjectType[Unit, Foo]
}
...
package object models { val FooType = Foo.FooType }
Erik
@erikdstock
This message was deleted
Erik
@erikdstock
Hi folks, I'm still having a hard time grokking when it is appropriate or necessary to use implicit vals the fieldsFn argument and so forth. It seems like no matter what I end up with a no implicit arguments found of type ValidOutType[...] on one specific enum type and some compile-time errors in at least one other case where it looks like i have defined the implicit val one line above its use - with no negative feedback from intellij.
One source of the complexity here seems to me that I am trying to pull these into separate traits [they have to be traits because of an implicit val ec: ExecutionContextExecutor], so I cannot easily mix them into each other
Erik
@erikdstock
Part of my confusion is with the docs and part is with the code i'm working with - being unsure if derive_Type is failing somewhere that I can't see due to macros, frequent use of both def & implicit val UserType: ObjectType[RequestServices, UserId]. In the validOutType case above that is also referring to a deriveEnumType (also defined in the same file) whose base trait is implemented entirely by case objects... Though i have to say, at this point this all is starting to feel like noisy word salad
kamisama-rney
@kamisama-rney
@erikdstock I suspect you're having issues with the JSON serialization. Which I admit the documentation doesn't give enough information on enums
@erikdstock Not sure which JSON parser you're I recommend you look into enumeratum which I used to get my Enum working with Circe
import enumeratum._
import sangria.macros.derive._
import sangria.schema._

sealed trait Platform extends EnumEntry
case object Platform extends CirceEnum[Platform] with Enum[Platform] {
  case object Android extends Platform
  case object iOS extends Platform

  val values: IndexedSeq[Platform] = findValues
}
And then include the correct marshalling package. Here's the ones I used for Circe
import io.circe.generic.auto._
import sangria.marshalling.FromInput
import sangria.marshalling.circe._
import sangria.schema._
import sangria.util.tag.@@
Enumeratum includes packages for all the common JSON parsers: Jackson, json4s, Argonaut...
Erik
@erikdstock
For now at least, we are using spray with a self: SprayJsonConversions => in every trait
I'm sorry I feel like I am running this chat with a lot of very basic questions
kamisama-rney
@kamisama-rney
Everyone has to learn sometime. No worries.
Erik
@erikdstock
I'm oscillating back and forth between thinking I have found something easier to read and understand and thinking this is getting very galaxy brained
kamisama-rney
@kamisama-rney
If you're planning to go forward with Spray you'll need to ensure the marshalling functions are declared implicit and visible with the marshaller
Sangria appears to support Circe's auto derivation functions for marshalling
And just a FYI: I just figured out how to handle the Enum marshalling last Thursday ;)
Erik
@erikdstock
Right. It's definitely working as-is so I am hestitant to make any big changes
but also being driven mad by these interdependent types, the overloaded method signatures and our existing mix of usages - an unimplemented def here, an implicit val there