Skip to content

Commit

Permalink
Fix for fragments with subtype refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
milessabin committed Dec 11, 2023
1 parent e0b85de commit 6f857e2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/sql/shared/src/main/scala/SqlMapping.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2987,7 +2987,7 @@ trait SqlMappingLike[F[_]] extends CirceMappingLike[F] with SqlModule[F] { self

val subtpes = narrows.map(_.subtpe)
val supertpe = context.tpe.underlying
assert(supertpe.underlying.isInterface || supertpe.underlying.isUnion)
assert(supertpe.underlying.isInterface || supertpe.underlying.isUnion || (subtpes.sizeCompare(1) == 0 && subtpes.head =:= supertpe))
subtpes.foreach(subtpe => assert(subtpe <:< supertpe))

val discriminator = discriminatorForType(context)
Expand Down
42 changes: 42 additions & 0 deletions modules/sql/shared/src/test/scala/SqlInterfacesSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,46 @@ trait SqlInterfacesSuite extends CatsEffectSuite {

assertWeaklyEqualIO(res, expected)
}

test("interface query with supertype fragment containing subtype refinement".only) {
val query = """
query {
films {
... EntityFields
}
}
fragment EntityFields on Entity {
id
... on Film {
rating
}
}
"""

val expected = json"""
{
"data" : {
"films" : [
{
"id" : "1",
"rating" : "PG"
},
{
"id" : "2",
"rating" : "U"
},
{
"id" : "3",
"rating" : "15"
}
]
}
}
"""

val res = mapping.compileAndRun(query)

assertWeaklyEqualIO(res, expected)
}
}

0 comments on commit 6f857e2

Please sign in to comment.