diff --git a/modules/core/src/main/scala/compiler.scala b/modules/core/src/main/scala/compiler.scala index 55c5281a..32fbca3d 100644 --- a/modules/core/src/main/scala/compiler.scala +++ b/modules/core/src/main/scala/compiler.scala @@ -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 @@ -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) diff --git a/modules/core/src/test/scala/introspection/IntrospectionSuite.scala b/modules/core/src/test/scala/introspection/IntrospectionSuite.scala index 397adf4b..a8840aa3 100644 --- a/modules/core/src/test/scala/introspection/IntrospectionSuite.scala +++ b/modules/core/src/test/scala/introspection/IntrospectionSuite.scala @@ -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 = """ {