Skip to content

Commit

Permalink
Merge pull request #623 from typelevel/topic/intro-inline-frags
Browse files Browse the repository at this point in the history
Fix handling of introspection types in inline fragments
  • Loading branch information
milessabin authored May 19, 2024
2 parents 6787efa + 1fdf4e5 commit d4d8508
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modules/core/src/main/scala/compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,10 @@ object QueryCompiler {
for {
s <- Elab.schema
c <- Elab.context
subtpe <- Elab.liftR(Result.fromOption(s.definition(tpnme), s"Unknown type '$tpnme' in type condition"))
subtpe <- Elab.liftR(Result.fromOption(
s.definition(tpnme).orElse(Introspection.schema.definition(tpnme)),
s"Unknown type '$tpnme' in type condition of inline fragment"
))
_ <- Elab.push(c.asType(subtpe), child)
ec <- transform(child)
_ <- Elab.pop
Expand Down Expand Up @@ -997,7 +1000,7 @@ object QueryCompiler {
case None =>
Elab.pure(ctpe)
case Some(tpnme) =>
Elab.liftR(s.definition(tpnme).toResult(s"Unknown type '$tpnme' in type condition inline fragment"))
Elab.liftR(s.definition(tpnme).toResult(s"Unknown type '$tpnme' in type condition of inline fragment"))
}
_ <- Elab.failure(s"Inline fragment with type condition '$subtpe' is not compatible with type '$ctpe'").whenA(!fragmentApplies(s, subtpe, ctpe))
_ <- Elab.push(c.asType(subtpe), child)
Expand Down
37 changes: 37 additions & 0 deletions modules/core/src/test/scala/introspection/IntrospectionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,43 @@ final class IntrospectionSuite extends CatsEffectSuite {
assertIO(res, Some(expected))
}

test("introspection types in inline fragments") {
val query = """
query IntrospectionQuery {
__type(name: "User") {
...TypeRef
}
}
fragment TypeRef on __Type {
name
kind
ofType {
name
... on __Type {
kind
}
}
}
"""

val expected = json"""
{
"data" : {
"__type" : {
"name" : "User",
"kind" : "OBJECT",
"ofType" : null
}
}
}
"""

val res = SmallMapping.compileAndRun(query)

assertIO(res, expected)
}

test("typename query") {
val query = """
{
Expand Down

0 comments on commit d4d8508

Please sign in to comment.