I was writing some tests using generated data buil...
# apollo-kotlin
s
I was writing some tests using generated data builders again, and I’ve again made the very subtle mistake where in one of my builders I did
Copy code
HomeQuery.Data(GiraffeFakeResolver) {
  contracts = listOf(
    buildContract {
      status = buildPendingStatus { }
      insuranceProviders = listOf(
        buildInsuranceProvider {},
      )
    },
  )
}
instead of
Copy code
HomeQuery.Data(GiraffeFakeResolver) {
  insuranceProviders = listOf(
    buildInsuranceProvider {},
  )
  contracts = listOf(
    buildContract {
      status = buildPendingStatus { }
    },
  )
}
which would be the right thing to do, as
insuranceProviders
is part of the top-level object, and not inside the
buildContract
lambda. Resulting in me getting a bit confused as I was reading back on my test and what it actually does. Part of me feels like what I should be doing instead is do
this.
before everything I do in these data builders, since that way I would be disallowed from accessing the parameter from the scope above of the one which I was in at that moment. Do you think this is our best bet when working with this? I’ve seen that @DslMarker exists, I’ve never really used it myself, but could it be the solution for this issue here? Or am I misunderstanding what it does?
a
I wonder if context receivers could help narrow scopes but may complicate the generated code
Definitely have seen similar things where we forget to set fields instead of assigning them. Or same thing where autocomplete shows nested this scope fields
s
I don’t think context receivers help here, in the call site you’re going to be in the same exact scope anyway, where you got both the outer and the inner scope as
this
currently, so you’ll still be able to call both as far as I understand.
Definitely have seen similar things where we forget to set fields instead of assigning them
What do you mean by this? Do you mean like doing
Copy code
buildContract {
  /* status = */ buildPendingStatus { }
},
So that the result of `buildFoo just is assigned to nothing? Like something that potentially this would fix?
👍 1
a
Yeah exactly
m
Happens to me all the time in Gradle scripts where I never know what the 'name' receiver is....
👆 1
Feels like
@DslMarker
would help for data builders
s
I can make an issue to track this if you wish 😊
m
Issues are good 👍
s