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

Can I set dummy variable inside dataclass and getting variable type is editable #5442

Closed
muslimmuda15 opened this issue Dec 6, 2023 · 5 comments

Comments

@muslimmuda15
Copy link

muslimmuda15 commented Dec 6, 2023

Question

After I generate apollo graphql, I getting data class like this
image

Can I add one variable again, like public var isActive: Boolean? and set some variable like paid and updated using var instead val?
this is my query
image

Thank you.

@BoD
Copy link
Contributor

BoD commented Dec 6, 2023

Hi!
The models are generated as data classes with vals as you can see, and at the moment it is not possible to generate vars instead. It's likely you will want to convert these to your own (non generated) models, but maybe you can tell us a bit more about your use case?

@muslimmuda15
Copy link
Author

muslimmuda15 commented Dec 6, 2023

in my flow, I want to update some item of order list List<OrderField> inside RecyclerView.
so I need some variables like paid and updated can be update programmatically and add extra variable outside query.
Maybe I can implementation like this:

data class MyCustomOrder(
    var isActive: Boolean,
    var paid: Boolean,
    var updated: Boolean,
    var myOrder: OrderField,
)

But this is not the clear code, because I will set them one by one again.

If the data class can set extra variable, and can change val into var, I think it will be more clear.

@BoD
Copy link
Contributor

BoD commented Dec 6, 2023

It looks like you could benefit from a way to have local only fields, which is a feature that exists on the web client but not yet on Apollo Kotlin. It's tracked in this issue: #2611.

For now you can wrap or convert the generated class into your own model with the additional fields.

@muslimmuda15
Copy link
Author

Yeah, in ReactJS, codegen is pretty clear and easy to used it.

@BoD
Copy link
Contributor

BoD commented Dec 7, 2023

We're tracking local fields in #2611 so closing this issue for now, but don't hesitate to open another issue if needed.

@BoD BoD closed this as completed Dec 7, 2023
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

2 participants