Hello hello ! Seeing a weird one regarding aliases...
# apollo-kotlin
m
Hello hello ! Seeing a weird one regarding aliases on fragments and fragment builders 🧵
Copy code
query ServerDrivenPageQuery($appointmentId: UUID!, $pageId: String!) {
    page(appointmentId: $appointmentId, pageId: $pageId) {
        ...ServerDrivenPageFragment
    }
}


fragment ServerDrivenPageFragment on Page {
    id
    sections {
        id
        components {
            __typename
            ...ItemRowFragment
            ...TimelineCardFragment
            ...ListCardFragment
        }
    }
}

fragment ItemRowFragment on ItemRow {
    rowLabel: label
    value
}

fragment TimelineCardFragment on TimelineCard {
    header
    cardLabel: label
    action {
        value
    }
    rows {
        ...ItemRowFragment
    }
}

fragment ListCardFragment on ListCard {
    header
    rows {
        ...ItemRowFragment
    }
}
Here Ive defined cardLabel and rowLabel aliases for the label value in both type
For testing purposes I create a fragment like
Copy code
val sut = ServerDrivenPageFragmentImpl.Data(FakeKrakenFieldResolver()) {
            id = "page_1"
            sections = listOf(
                buildUiSection {
                    id = "section_1"
                    components = emptyList()
                },
                buildUiSection {
                    id = "section_2"
                    components = listOf(

                        buildItemRow {
                            label = "Label 1"
                            value = "Value 1"
                        },
                        buildListCard {
                            header = "List Card Header"
                            rows = listOf(
                                buildItemRow {
                                    label = "List Item 2"
                                    value = "List Value 2"
                                },
                                buildItemRow {
                                    label = "List Item 3"
                                    value = "List Value 3"
                                },
                            )
                        },
                        buildTimelineCard {
                            header = "Timeline Card Header"
                            label = "Card Label"
                            action = buildHyperlink {
                                value = "<https://example.com/action>"
                            }
                            rows = listOf(
                                buildItemRow {
                                    label = "Timeline Item 4"
                                    value = "Timeline Value 4"
                                },
                            )
                        },
                        buildOtherUiComponent("__forcedNull") {
                        },
                    )
                },
            )
        }
when I tray to assert to my mapped values it fails case the item rows ( all of them ) have the default value for label rather than the ones I provide on the fragment impl
Copy code
public class ItemRowBuilder(
  customScalarAdapters: CustomScalarAdapters,
) : ObjectBuilder<ItemRowMap>(customScalarAdapters) {
  public var label: String by __fields

  public var `value`: String by __fields

  init {
    __typename = "ItemRow"}

  override fun build(): ItemRowMap = ItemRowMap(__fields)
}
I can see the generated builder expose label rather than rowLabel but that should not be an issue should be? What am i misisng for my value to be picked up?
m
What version is this with?
If 4.x, any chance you can try with 5.x? There were a couple of changes there related to data builders
m
It is 4.x yeah, Will give it a go at 5.x just for curiosity but don't think Ill be able to upgrade our project 😅 ( unless its very straight forward)
m
Most of the update should be relatively straightforward. Main areas of change are data builders and compiler plugins
Something that looks a bit off is this:
Copy code
buildItemRow {
                            label = "Label 1"
                            value = "Value 1"
                        },
If you're using aliases, I would expect something more like so:
Copy code
buildItemRow {
                            this["rowLabel"] = "Label 1"
                            value = "Value 1"
                        },
https://www.apollographql.com/docs/kotlin/testing/data-builders#aliases
m
I absolutely missed this one and does totally work
thanks!
m
Nice!
Feel free to still try 5.0.0-alpha.2 🙂
m
yep will start a spike on that one!
❤️ 1
m
Nice!! Let us know how that goes!
m
sure thing