Skip to content

Commit 761b0b0

Browse files
fix: TypeReference support
1 parent 0168729 commit 761b0b0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Sources/GraphQL/Execution/Execute.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,21 @@ func completeValue(
969969
)
970970
}
971971

972+
// If field type is a TypeReference, find the type itself.
973+
if
974+
let returnType = returnType as? GraphQLTypeReference,
975+
let referencedType = info.schema.typeMap[returnType.name]
976+
{
977+
return try completeValue(
978+
exeContext: exeContext,
979+
returnType: referencedType,
980+
fieldASTs: fieldASTs,
981+
info: info,
982+
path: path,
983+
result: .success(exeContext.eventLoopGroup.any().makeSucceededFuture(result))
984+
)
985+
}
986+
972987
// Not reachable. All possible output types have been considered.
973988
throw GraphQLError(
974989
message: "Cannot complete value of unexpected type \"\(returnType)\"."

Sources/GraphQL/Execution/Values.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,16 @@ func getVariableValue(
8888
definitionAST: VariableDefinition,
8989
input: Map
9090
) throws -> Map {
91-
let type = typeFromAST(schema: schema, inputTypeAST: definitionAST.type)
91+
var type = typeFromAST(schema: schema, inputTypeAST: definitionAST.type)
9292
let variable = definitionAST.variable
9393

94+
if let typeReference = type as? GraphQLTypeReference {
95+
guard let referencedType = schema.typeMap[typeReference.name] else {
96+
throw GraphQLError(message: "Referenced type \(typeReference.name) not found")
97+
}
98+
type = referencedType
99+
}
100+
94101
guard let inputType = type as? GraphQLInputType else {
95102
throw GraphQLError(
96103
message:

0 commit comments

Comments
 (0)