0

This is my model class:

final case class Organization(
    id: UUID,
    name: String
)

My Queries class looks like this:

case class Queries(
    organizations: URIO[DatabaseService, List[Organization]]
)

And I have a service that looks like this:

class GraphQLService:
    def getOrganizations =
        for
            db <- ZIO.service[DatabaseService]
            orgs <- db.organizations
        yield orgs

    val queries = Queries(getOrganizations.orDie)

    val resolver = RootResolver(queries)

    val api = graphQL(resolver)

db.organizations returns ZIO[Any, SQLException, List[Organization]].

That last line gets the following error:

Cannot find a Schema for type zio.URIO[io.livefeeds.db.DatabaseService, 
  List[io.livefeeds.db.model.Organization]
].

Caliban derives a Schema automatically for basic Scala types, case classes and sealed traits, but
you need to manually provide an implicit Schema for other types that could be nested in zio.URIO[io.livefeeds.db.DatabaseService, 
  List[io.livefeeds.db.model.Organization]
].
If you use a custom type as an argument, you also need to provide an implicit ArgBuilder for that type.
See https://ghostdogpr.github.io/caliban/docs/schema.html for more information.
.
I found:

    caliban.schema.Schema.gen[Any, 
      
        zio.ZIO[io.livefeeds.db.DatabaseService, Nothing, 
          List[io.livefeeds.db.model.Organization]
        ]
      
    ]

But given instance gen in trait SchemaDerivation does not match type caliban.schema.Schema[Any, 
  zio.URIO[io.livefeeds.db.DatabaseService, 
    List[io.livefeeds.db.model.Organization]
  ]
].
    val api = graphQL(resolver)

As far as I can tell, I'm not using anything unsupported. The docs say that ZIO[R, Nothing, A] maps to A. What am I missing?

Isvara
  • 3,403
  • 1
  • 28
  • 42

1 Answers1

1

Turns out that the schema needed to know about my depedencies, so

val api = graphQL(resolver)

became

val api = graphQL[DatabaseService, Queries, Unit, Unit](resolver)
Isvara
  • 3,403
  • 1
  • 28
  • 42