Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class GraphQLClientGenerator(
// shared types
sharedTypes.putAll(context.enumClassToTypeSpecs.mapValues { listOf(it.value) })
sharedTypes.putAll(context.inputClassToTypeSpecs.mapValues { listOf(it.value) })
sharedTypes.putAll(context.responseClassToTypeSpecs.mapValues { listOf(it.value) })
context.scalarClassToConverterTypeSpecs
.values
.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data class GraphQLClientGeneratorContext(
// shared type caches
val enumClassToTypeSpecs: MutableMap<ClassName, TypeSpec> = mutableMapOf()
val inputClassToTypeSpecs: MutableMap<ClassName, TypeSpec> = mutableMapOf()
val responseClassToTypeSpecs: MutableMap<ClassName, TypeSpec> = mutableMapOf()
val scalarClassToConverterTypeSpecs: MutableMap<ClassName, ScalarConverterInfo> = mutableMapOf()
val typeAliases: MutableMap<String, TypeAliasSpec> = mutableMapOf()
internal fun isTypeAlias(typeName: String) = typeAliases.containsKey(typeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,16 @@ private fun calculateSelectedFields(
}
return result
}

/**
* Find an existing shared response type for the given GraphQL type name
*/
private fun findSharedResponseType(
context: GraphQLClientGeneratorContext,
graphQLTypeName: String
): ClassName? {
return context.responseClassToTypeSpecs.keys.find { className ->
className.simpleName == graphQLTypeName &&
className.packageName.endsWith(".responses")
}
}