-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
619 additions
and
82 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...ommonMain/kotlin/com/apollographql/apollo3/cache/normalized/api/EmbeddedFieldsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.apollographql.apollo3.cache.normalized.api | ||
|
||
import com.apollographql.apollo3.annotations.ApolloExperimental | ||
import com.apollographql.apollo3.api.CompiledNamedType | ||
import com.apollographql.apollo3.api.InterfaceType | ||
import com.apollographql.apollo3.api.ObjectType | ||
|
||
@ApolloExperimental | ||
interface EmbeddedFieldsProvider { | ||
fun getEmbeddedFields(context: EmbeddedFieldsContext): List<String> | ||
} | ||
|
||
@ApolloExperimental | ||
class EmbeddedFieldsContext( | ||
val parentType: CompiledNamedType, | ||
) | ||
|
||
@ApolloExperimental | ||
object DefaultEmbeddedFieldsProvider : EmbeddedFieldsProvider { | ||
override fun getEmbeddedFields(context: EmbeddedFieldsContext): List<String> { | ||
return context.parentType.embeddedFields | ||
} | ||
} | ||
|
||
private val CompiledNamedType.embeddedFields: List<String> | ||
get() = when (this) { | ||
is ObjectType -> embeddedFields | ||
is InterfaceType -> embeddedFields | ||
else -> emptyList() | ||
} | ||
|
||
@ApolloExperimental | ||
class ConnectionEmbeddedFieldsProvider( | ||
connectionFields: Map<String, List<String>>, | ||
connectionTypes: Set<String>, | ||
) : EmbeddedFieldsProvider { | ||
companion object { | ||
private val connectionFieldsToEmbed = listOf("pageInfo", "edges") | ||
} | ||
|
||
private val embeddedFields = connectionFields + connectionTypes.associateWith { connectionFieldsToEmbed } | ||
|
||
override fun getEmbeddedFields(context: EmbeddedFieldsContext): List<String> { | ||
return embeddedFields[context.parentType.name].orEmpty() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.