From ad677b0c1f383d780eeb6e92c1f25f4bab3f4e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20W=C3=A4rnsberg?= Date: Wed, 8 Sep 2021 10:58:17 +0200 Subject: [PATCH] fix: Allow other implementations of SchemaLoader (#1036) --- tools/src/main/scala/caliban/tools/SchemaLoader.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/src/main/scala/caliban/tools/SchemaLoader.scala b/tools/src/main/scala/caliban/tools/SchemaLoader.scala index e9a783eae..78b477d37 100644 --- a/tools/src/main/scala/caliban/tools/SchemaLoader.scala +++ b/tools/src/main/scala/caliban/tools/SchemaLoader.scala @@ -5,7 +5,7 @@ import caliban.parsing.Parser import caliban.parsing.adt.Document import zio.{ Task, UIO } -sealed trait SchemaLoader { +trait SchemaLoader { def load: Task[Document] } @@ -13,6 +13,9 @@ 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)) @@ -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 =