-
Notifications
You must be signed in to change notification settings - Fork 661
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
generateOptionalOperationVariables
setting is ignored.
#4747
Comments
Hi! The option is only taken into account for operation variables - the rationale being that when you write an operation to accept an argument, it is usually because you want to pass a value for it, but that is not as obvious for input fields. |
Would you mind elaborating? Are you suggesting that the setting only applies to "top-level" variables and not variables in an input model? |
Sure thing! This means that if you write an operation that accept a variable that is nullable, e.g: query MyQuery($myVariable: String) {
...
} Then, by default, this will be generated with an data class MyQuery(val myVariable: Optional<String?>) {...} But you can use the data class MyQuery(val myVariable: String?) {...} However if your schema defines input fields that have nullable fields, e.g. input SignupMemberInput {
cellPhone: String
} these will always be generated with |
About supporting this also on input objects there may be a valid use-case, would you mind telling us a bit more about your schema and what you are trying to do? |
Ok, thank you for the example! It's appreciated. I am migrating an application to Apollo 3 and many, if not most, of the queries and mutations in the application use input model objects with nested fields instead of independent "top-level" variables like the ones you referenced. Is there a way to migrate those queries and mutations to Apollo 3 without having to rewrite every input argument to use val mutation = SignupMemberMutation.builder().input(
SignupMemberInput.builder().apply {
dob(Utils.changeDateFormat(user.dobMMDDYYYY, "MM/dd/yyyy", "yyyy-MM-dd"))
firstName(user.firstName)
lastName(user.lastName)
ssLast4(user.ssnLastFour)
email(user.email)
cellPhone(user.phone)
password(user.password)
acceptedTos(true)
formIds(formIds)
medium(ConsentMediumEnum.ANDROID)
}.build()
).build() After reading the documentation, I'm fairly certain that would need to be rewritten in Apollo 3 to: val input = SignupMemberInput(
dob = Utils.changeDateFormat(user.dobMMDDYYYY, "MM/dd/yyyy", "yyyy-MM-dd"),
firstName = Optional.Present(user.firstName),
lastName = user.lastName,
ssLast4 = Optional.Present(user.ssnLastFour),
email = user.email,
cellPhone = Optional.Present(user.phone),
password = user.password,
acceptedTos = true,
formIds = Optional.Present(formIds),
medium = Optional.Present(ConsentMediumEnum.android)
)
val mutation = SignupMemberMutation(input) Is that correct? Is there a way to configure Apollo to generate nested fields in input objects as simple nullables?
I am attempting to upgrade an application to Apollo 3 using the migration guide. The application has about 6,000 lines of queries, so rewriting every input constructor to use |
Thanks a lot for the context, that helps a ton! As a reminder, the reason the That being said, I can see that when converting your own classes to the input models generated by Apollo, the Optionals can add some friction, including in your case, where you're migrating existing code. This is not a great solution, but you could generate Java models (with For the future, we're thinking of possible ideas to help there:
|
@BoD Thank you. I'll investigate the feasibility of using those configuration options for Java models, though I understand Kotlin models are probably preferable. Regarding the options you listed, a way of obscuring the concept of Regardless, I will assume the Thank you for linking that blog post! I read it and thought it was helpful. |
That's correct 👍 |
@BoD Thank you. I'm going to close this issue as the original question has been addressed.
I have attempted to use those two configuration options. While they do force Java models to be generated, the generated models seem to be quite different than the ones generated via Apollo v2. For example: try {
val response = client.get().query(query).execute()
if (response.hasErrors()) {
onError(response.errors?.first()?.message ?: genericErrorMsg, false)
} else {
val data = response.data!!
data.coverageCheck
if (data.coverageCheck() != null) {
onSuccess(
data.coverageCheck()!!.coverageStatus(),
data.coverageCheck()!!.accountStatus(),
data.coverageCheck()!!.coveredBy()?.name(),
data.coverageCheck()!!.coveredBy()?.id(),
data.coverageCheck()!!.coveredBy()?.mfaRequired(),
data.coverageCheck()!!.signupToken()
)
} else {
onError(genericErrorMsg, false)
}
}
} catch (exception: ApolloException) {
onError("ApolloException ${exception.message}", true)
return
}
I have also attempted to perform an upgrade to Apollo v3 using the new compatibility modes (
I suspect many of the queries and mutations I referenced earlier will need to be rewritten, regardless of whether or not Java models are used. |
|
Version
3.7.4
Summary
The
generateOptionalOperationVariables
option seems to be ignored.Configuration:
A generated class for a mutation input:
According to the documentation, the relevant variables should be nullable.
Steps to reproduce the behavior
Use Apollo 3.7.4 with the
generateOptionalOperationVariables.set(false)
setting and generate a mutation input with optional values.The text was updated successfully, but these errors were encountered: