Skip to content
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

⚙️ Low level compiler APIs #4026

Closed
martinbonnin opened this issue Apr 13, 2022 · 8 comments
Closed

⚙️ Low level compiler APIs #4026

martinbonnin opened this issue Apr 13, 2022 · 8 comments
Assignees
Milestone

Comments

@martinbonnin
Copy link
Contributor

It has come up a few times that tweaking the compiler output is desired. This issue is to brainstorm about possible extension points for the compiler and collect use cases.

One of the challenges is going to be how to expose that to Gradle. Because every Task input must be serializable, providing code is not easy. OperationOutputGenerator for an example uses a small workaround that the user has to manage a version by hand, which is not ideal for code that might change more often.

Another one is that this will certainly require keeping the KotlinPoet classes in the R8 configuration, which means it's more likely to clash with other buildscript dependencies.

@BoD
Copy link
Contributor

BoD commented Apr 19, 2022

Another potential use-case: have the generated models implement Serializable or Parcelable so they can easily be passed around in Intents, or in a navigation graph.

@martinbonnin
Copy link
Contributor Author

martinbonnin commented Apr 19, 2022

I don't think the Parcelable use case holds. Serializing a model usually requires some context (variables, scalar adapters, defer labels, etc...) so it's better addressed through serialization using fromJson/toJson instead of implementing Parcelable/Serializable

@BoD BoD added the 📜 Feedback Wanted This feature/API needs more use cases and details before it can be implemented. label May 17, 2022
@BoD
Copy link
Contributor

BoD commented Aug 11, 2022

Another potential use case: the ability to make the generated types internal or not depending on custom logic (see #4334)

@AnkitPatanaik
Copy link

Another potential use case: Adding default values to Apollo Models w/o writing a custom directive

i.e.

query MyQuery {
   name 
   nullable_name // this is a String? type
}

// response
{
  name: "ankit",
  nullable_name: null
}

// ideal response
{
  name: "ankit",
  nullable_name: "my_default_name"
}

@BoD BoD mentioned this issue Oct 24, 2022
@jpvajda jpvajda removed the 📜 Feedback Wanted This feature/API needs more use cases and details before it can be implemented. label Oct 24, 2022
@jpvajda jpvajda added this to the Release 3.7 milestone Oct 24, 2022
@BoD
Copy link
Contributor

BoD commented Nov 3, 2022

This can also be used to add getters/setters in Java models (#4210)

@BoD
Copy link
Contributor

BoD commented Nov 3, 2022

Also, #4253

@BoD
Copy link
Contributor

BoD commented Nov 4, 2022

With #4210, hooks can now be set to intercept and manipulate KotlinPoet / JavaPoet builders before they are written to the disk. A few examples of using it are available here. This will be in the next release, in the meantime it can be tried out with the snapshots. The API is marked as experimental for now, feedback is appreciated!

@BoD
Copy link
Contributor

BoD commented Nov 9, 2022

Available in 3.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants