-
Notifications
You must be signed in to change notification settings - Fork 657
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
[Codegen] Add CompiledArgumentDefinition #5797
Conversation
…ledArgumentDefinition(...)
… usage in operations
…rgument usage in operations
✅ Deploy Preview for apollo-android-docs canceled.
|
libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/UsedCoordinates.kt
Show resolved
Hide resolved
val parentType: String, | ||
val parentField: 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.
can you merge parentType
and parentField
(and name
) in an id
field like in IrModel.id
that you can later use to resolve the argument definition classname for that id?
I'm trying to avoid GraphQL things in the IR. It's OK to have opaque ids but IR doesn't need to know about GraphQL names.
private fun UsedCoordinates.putAllArguments( | ||
parentType: String, | ||
selections: List<GQLSelection>, | ||
allFragmentDefinitions: Map<String, GQLFragmentDefinition>, | ||
) { |
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.
If you end up keeping this, allFragmentDefinitions
is in the context already, I think you can skip it here.
Also side note: yet another thing that would be easier to do with a proper traversal API.
...src/test/graphql/com/example/antlr_tokens/java/operationBased/used-coordinates.json.expected
Outdated
Show resolved
Hide resolved
// When a field with arguments is selected, its parent type is referenced in the compiled selections | ||
if (first.definitionHasArguments) { | ||
usedCoordinates.putType(first.parentType) |
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.
Could you add all the arguments here instead of calling UsedCoordinates.putAllArguments
at the end of the process? You'll probably have to add arguments
to the CollectedField
but it's colocating everything.
@@ -62,6 +66,10 @@ internal data class IrObject( | |||
val deprecationReason: String?, | |||
val embeddedFields: List<String>, | |||
val mapProperties: List<IrMapProperty>, | |||
/** | |||
* Only contains fields that have arguments used in operations. |
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.
I think it's OK to skip that comment since it's the whole premise of the IR that it matches the target and not the GraphQL schema.
We could add a more general comment how these things are decided in IrOperationBuilder
and link from here though.
/** | ||
* The compile-time value of that argument. | ||
* | ||
* Can be the defaultValue if no argument is defined in the operation. |
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.
Didn't we go for "no need for the schema defaultValue
"?
...pollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/SelectionSetsBuilder.kt
Show resolved
Hide resolved
…on. Instead, store ids to resolve them and necessary info for the codegen.
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.
👍
@@ -33,6 +33,7 @@ enum class ResolverKeyKind { | |||
Schema, | |||
CustomScalarAdapters, | |||
Pagination, | |||
ArgumentDefinition, |
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.
For later: we can use the coordinate to lookup the matching kotlin instead of adding a new kind each time.
fun id(type: String, field: String, argument: String) = "$type.$field.$argument" | ||
fun propertyName(fieldName: String, argumentName: String) = "__${fieldName}_${argumentName}" |
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.
For later: we should come up with some rules about symbols. Are __
to escape nameclashes or a signal that it is not meant to be called directly. It's not 100% clear at the moment
Introduce
CompiledArgumentDefinition
instead of storing schema argument details (isKey, isPagination) inCompiledArgument
They are added as fields inside the
Type
class, with the form__fieldName__argumentName
To limit the size of the generated code, track arguments that are used by operations and output only the definition for those
UsedCoordinates
is introduced, to avoid manipulating maps directly.CodegenTest
inused-coordinates.json
filesBehavior change: only the specified arguments values are set to the
CompiledArgument
, and not the default value from the schema. This makes the note sayingThe argument defaultValues are not added to the name
in the Kdoc ofnameWithArguments()
true.Resolves #5781