Skip to content

Commit ce9efb9

Browse files
committed
remove node constraint type
1 parent 6a74066 commit ce9efb9

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

core/src/main/scala/caliban/relay/Node.scala

Lines changed: 0 additions & 5 deletions
This file was deleted.

core/src/main/scala/caliban/relay/NodeResolver.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import caliban.schema.Step.{ MetadataFunctionStep, QueryStep }
77
import caliban.schema.{ Schema, Step }
88
import zio.query.ZQuery
99

10+
/**
11+
* A resolver which is used when attempting to materialize different implementations of the `Node` interface
12+
* @tparam R
13+
* @tparam ID
14+
*/
1015
trait NodeResolver[-R, ID] {
1116
def resolve(id: ID): Step[R]
1217
def toType: __Type
@@ -18,7 +23,7 @@ object NodeResolver {
1823

1924
def fromMetadata[ID]: FromMetadataPartiallyApplied[ID] = new FromMetadataPartiallyApplied[ID]
2025

21-
def fromOption[R, ID, T <: Node[ID]](
26+
def fromOption[R, ID, T](
2227
resolver: ID => Option[T]
2328
)(implicit schema: Schema[R, T]): NodeResolver[R, ID] =
2429
new NodeResolver[R, ID] {
@@ -31,7 +36,7 @@ object NodeResolver {
3136
override def toType: __Type = schema.toType_()
3237
}
3338

34-
def fromEither[R, ID, T <: Node[ID]](
39+
def fromEither[R, ID, T](
3540
resolver: ID => Either[CalibanError, Option[T]]
3641
)(implicit schema: Schema[R, T]): NodeResolver[R, ID] =
3742
new NodeResolver[R, ID] {
@@ -45,7 +50,7 @@ object NodeResolver {
4550
override def toType: __Type = schema.toType_()
4651
}
4752

48-
def fromZIO[R, ID, T <: Node[ID]](
53+
def fromZIO[R, ID, T](
4954
resolver: ID => ZQuery[R, CalibanError, Option[T]]
5055
)(implicit schema: Schema[R, T]): NodeResolver[R, ID] =
5156
new NodeResolver[R, ID] {
@@ -55,7 +60,7 @@ object NodeResolver {
5560
override def toType: __Type = schema.toType_()
5661
}
5762

58-
def fromQuery[R, ID, T <: Node[ID]](
63+
def fromQuery[R, ID, T](
5964
resolver: ID => ZQuery[R, CalibanError, Option[T]]
6065
)(implicit schema: Schema[R, T]): NodeResolver[R, ID] =
6166
new NodeResolver[R, ID] {
@@ -66,7 +71,7 @@ object NodeResolver {
6671
}
6772

6873
final class FromPartiallyApplied[ID](val dummy: Boolean = false) {
69-
def apply[R, T <: Node[ID]](
74+
def apply[R, T](
7075
resolver: ID => ZQuery[R, CalibanError, Option[T]]
7176
)(implicit schema: Schema[R, T]): NodeResolver[R, ID] = new NodeResolver[R, ID] {
7277
override def resolve(id: ID): Step[R] =
@@ -77,7 +82,7 @@ object NodeResolver {
7782
}
7883

7984
final class FromMetadataPartiallyApplied[ID](val dummy: Boolean = false) {
80-
def apply[R, T <: Node[ID]](
85+
def apply[R, T](
8186
resolver: Field => ID => ZQuery[R, CalibanError, Option[T]]
8287
)(implicit schema: Schema[R, T]): NodeResolver[R, ID] = new NodeResolver[R, ID] {
8388
override def resolve(id: ID): Step[R] =

core/src/main/scala/caliban/relay/RelaySupport.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ object RelaySupport {
7575

7676
(original |+| graphQL[R, Query, Unit, Unit](
7777
RootResolver(
78-
Query(node = args => ZQuery.fromEither(typeResolver.resolve(args.id)).map(Identifier(_, args.id)))
78+
Query(node =
79+
args =>
80+
typeResolver.resolve(args.id) match {
81+
case Left(error) => ZQuery.fail(error)
82+
case Right(typename) => ZQuery.succeed(Identifier(typename, args.id))
83+
}
84+
)
7985
)
8086
)).transform(transformer)
8187
}

core/src/test/scala/caliban/relay/GlobalIdentifierSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ object GlobalIdentifierSpec extends ZIOSpecDefault {
3939
}
4040
}
4141

42-
case class Ship(id: ID, name: String, purpose: String) extends Node[ID]
43-
case class Character(id: ID, name: String) extends Node[ID]
42+
case class Ship(id: ID, name: String, purpose: String)
43+
case class Character(id: ID, name: String)
4444
case class Query(
4545
characters: List[Character],
4646
ships: List[Ship]

0 commit comments

Comments
 (0)