-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache pagination: add FieldNameGenerator and EmbeddedFieldsProvider #5772
Conversation
✅ Deploy Preview for apollo-android-docs canceled.
|
public synthetic fun <init> (Ljava/lang/String;Lcom/apollographql/apollo3/api/Optional;ZZLkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
public final fun getName ()Ljava/lang/String; | ||
public synthetic fun <init> (Lcom/apollographql/apollo3/api/CompiledArgumentDefinition;Lcom/apollographql/apollo3/api/Optional;Lkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
public final fun getDefinition ()Lcom/apollographql/apollo3/api/CompiledArgumentDefinition; | ||
public final fun getValue ()Lcom/apollographql/apollo3/api/Optional; | ||
public final fun isKey ()Z |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep getName
and isKey
as deprecated?
CompiledArgument.Builder(CompiledArgumentDefinition.Builder("episode").build()).value("JEDI").build(), | ||
CompiledArgument.Builder(CompiledArgumentDefinition.Builder("starsFloat").build()).value(9.9).build(), | ||
CompiledArgument.Builder(CompiledArgumentDefinition.Builder("starsInt").build()).value(10).build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about generating the definitions only once and referencing them here?
First:
// type
class Query {
// field
class Reviews {
companion object {
// argument
val episode = CompiledArgumentDefinition.Builder("episode")build()
val starsFloat = CompiledArgumentDefinition.Builder("starsFloat").build()
}
}
companion object {
val type: ObjectType = ObjectType.Builder(name = "Query").build()
}
}
Then
CompiledArgument.Builder(Query.Reviews.episode).value("JEDI").build()
interface EmbeddedFieldsProvider { | ||
fun getEmbeddedFields(context: EmbeddedFieldsContext): List<String> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make this even more typesafe and also save a few string comparisons
interface CompiledFieldDefinition
// type
class Query {
// field
class Reviews {
companion object {
// argument
val episode = CompiledArgumentDefinition.Builder("episode").build()
val starsFloat = CompiledArgumentDefinition.Builder("starsFloat").build()
val __definition = object: CompiledFieldDefinition {}
}
}
companion object {
val type: ObjectType = ObjectType.Builder(name = "Query").build()
}
}
And then
interface EmbeddedFieldsProvider {
fun getEmbeddedFields(context: EmbeddedFieldsContext): List<CompiledFieldDefinition>
Not sure if it's worth it though...
3543587
to
a45c0ff
Compare
In this PR, 2 APIs are added:
FieldNameGenerator
to control how field names in records are computed. The default implementation usesCompiledField.nameWithArguments
, and a Relay awareConnectionFieldNameGenerator
version is also provided. This unlocks cases where the pagination arguments are inside an input type. This is a reprise of this previous PR.EmbeddedFieldProvider
to control which fields should be embedded in a record. The default implementation usesCompiledNamedType.embeddedFields
, and a Relay awareConnectionEmbeddedFieldsProvider
version is also provided.Also, a(this will go in a separate PR)CompilerArgumentDefinition
is introduced, to more cleanly separate an argument value vs its definition (and sorry this makes this PR big with the.expected
- I can separate this to another PR if preferred!).With this, the Pagination mechanism is usable without any directives in
extra.graphqls
(#5666), an example is given inConnectionProgrammaticPaginationTest
.