Skip to content

Commit

Permalink
Fix graphql empty queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Nov 1, 2024
1 parent 26da3a0 commit 29486f4
Showing 1 changed file with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,50 +108,58 @@ class BangumiRelatedPeopleService(

private suspend fun queryGraphQLCharacters(
ids: Sequence<Int>,
) = client.executeGraphQL(
"BangumiRelatedPeopleService.queryGraphQLCharacters",
"""
query MyQuery {
${ids.distinct().joinToString("\n") { "c${it}: character(id: ${it}) { ...CharacterFragment }" }}
}
fragment CharacterFragment on Character {
infobox {
values {
k
v
): List<QCharacterOrPerson> {
val distinctIds = ids.distinct().toList()
if (distinctIds.isEmpty()) return emptyList()
return client.executeGraphQL(
"BangumiRelatedPeopleService.queryGraphQLCharacters",
"""
query MyQuery {
${distinctIds.joinToString("\n") { "c${it}: character(id: ${it}) { ...CharacterFragment }" }}
}
key
}
id
}
""".trimIndent(),
)["data"]!!.jsonObject.values.map {
json.decodeFromJsonElement(QCharacterOrPerson.serializer(), it)
fragment CharacterFragment on Character {
infobox {
values {
k
v
}
key
}
id
}
""".trimIndent(),
)["data"]!!.jsonObject.values.map {
json.decodeFromJsonElement(QCharacterOrPerson.serializer(), it)
}
}

private suspend fun queryGraphQLPersons(
ids: Sequence<Int>,
) = client.executeGraphQL(
"BangumiRelatedPeopleService.queryGraphQLPersons",
"""
query MyQuery {
${ids.joinToString("\n") { "c${it}: person(id: ${it}) { ...CharacterFragment }" }}
}
fragment CharacterFragment on Person {
infobox {
values {
k
v
): List<QCharacterOrPerson> {
val distinctIds = ids.distinct().toList()
if (distinctIds.isEmpty()) return emptyList()
return client.executeGraphQL(
"BangumiRelatedPeopleService.queryGraphQLPersons",
"""
query MyQuery {
${distinctIds.joinToString("\n") { "c${it}: person(id: ${it}) { ...CharacterFragment }" }}
}
key
}
id
}
""".trimIndent(),
)["data"]!!.jsonObject.values.map {
json.decodeFromJsonElement(QCharacterOrPerson.serializer(), it)
fragment CharacterFragment on Person {
infobox {
values {
k
v
}
key
}
id
}
""".trimIndent(),
)["data"]!!.jsonObject.values.map {
json.decodeFromJsonElement(QCharacterOrPerson.serializer(), it)
}
}


Expand Down

0 comments on commit 29486f4

Please sign in to comment.