artemis icon indicating copy to clipboard operation
artemis copied to clipboard

How to pass nested fragments

Open baconcheese113 opened this issue 3 years ago • 2 comments

If I have a query and fragments like below

query Home {
  user {
    id
    ...fragment1_user
  }
}

fragment fragment1_user on User {
  __typename
  id
  firstName
  ...fragment2a_user
  ...fragment2b_user
}

fragment fragment2a_user on User {
   __typename
  id
  lastName
}

fragment fragment2b_user on User {
  __typename
  id
  email
}

When I try to pass the props to their child widgets inside the Fragment1 Widget:

Fragment2aWidget(userFrag: widget.userFrag),
Fragment2bWidget(userFrag: widget.userFrag),

I get the following errors:

The argument type 'Fragment1UserMixin' can't be assigned to the parameter type 'Fragment2aUserMixin'. The argument type 'Fragment1UserMixin' can't be assigned to the parameter type 'Fragment2bUserMixin'.

From the Home to Fragment1 widgets I see I'm able to pass Home$Query$User to the Fragment1UserMixin type, but I can't pass the others. I could probably just cast to the child mixin types, but that prevents static analysis on the values I'm passing in.

Am I missing something?

baconcheese113 avatar Jun 21 '22 03:06 baconcheese113

Look at how the code is generated. As far as I understand- it’s mostly relates to how dart type system work. Maybe you’ll be able to find suitable approach

vasilich6107 avatar Jun 27 '22 22:06 vasilich6107

It appears like the runtimeTypes aren't changing, that's preventing passing nested fragments farther down the widget tree

baconcheese113 avatar Jul 01 '22 02:07 baconcheese113