Skip to content

Commit

Permalink
fix: Allow other implementations of SchemaLoader (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
frekw authored Sep 8, 2021
1 parent ea3a017 commit ad677b0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/src/main/scala/caliban/tools/SchemaLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import caliban.parsing.Parser
import caliban.parsing.adt.Document
import zio.{ Task, UIO }

sealed trait SchemaLoader {
trait SchemaLoader {
def load: Task[Document]
}

object SchemaLoader {
case class FromCaliban private (api: GraphQL[_]) extends SchemaLoader {
override def load: Task[Document] = UIO(api.toDocument)
}
case class FromDocument private (doc: Document) extends SchemaLoader {
override def load: Task[Document] = UIO(doc)
}
case class FromFile private (path: String) extends SchemaLoader {
override def load: Task[Document] =
Task(scala.io.Source.fromFile(path))
Expand All @@ -27,6 +30,7 @@ object SchemaLoader {
}

def fromCaliban[R](api: GraphQL[R]): SchemaLoader = FromCaliban(api)
def fromDocument(doc: Document): SchemaLoader = FromDocument(doc)
def fromFile(path: String): SchemaLoader = FromFile(path)
def fromString(schema: String): SchemaLoader = FromString(schema)
def fromIntrospection(url: String, headers: Option[List[Options.Header]]): SchemaLoader =
Expand Down

0 comments on commit ad677b0

Please sign in to comment.