swift-graphql icon indicating copy to clipboard operation
swift-graphql copied to clipboard

Optional lists? optional().list.optional()

Open tzdesign opened this issue 1 year ago • 0 comments

Describe the bug I'm not sure if it's a bug or I just don't get the types yet.

I have a shop with optional categories and a M2M relation.


extension Objects.ShopFairShop {
 public static func categories<T>(
    filter: OptionalArgument<InputObjects.ShopFairShopShopFairCategoryFilter> = .init(),
    sort: OptionalArgument<[OptionalArgument<String>]> = .init(),
    limit: OptionalArgument<Int> = .init(), offset: OptionalArgument<Int> = .init(),
    page: OptionalArgument<Int> = .init(), search: OptionalArgument<String> = .init(),
    selection: Selection<T, [Objects.ShopFairShopShopFairCategory?]?>
  ) -> Selection<T, Objects.ShopFairShop> {
    Selection<T, Objects.ShopFairShop> {
      try $0.categories(
        filter: filter, sort: sort, limit: limit, offset: offset, page: page, search: search,
        selection: selection)
    }
  }
}

At least I get to this:

let categorySelection = Selection.ShopFairShopShopFairCategory{
            try $0.shopFairCategoryId(selection: Selection.ShopFairCategory{ try $0.name() ?? "" }.optional())
        }.optional().list

But I need to get the list optional as well. Don't know how.

If I do this:

let categorySelection = Selection.ShopFairShopShopFairCategory{
            try $0.shopFairCategoryId(selection: Selection.ShopFairCategory{ try $0.name() ?? "" }.optional())
        }.optional().list.optional()

It gives me:

Generic parameter 'UnwrappedT' could not be inferred

To Reproduce

My graph is not public yet, so It's hard to give a repo

Expected behavior My expectation was, that list.optional would give me:

Selection<[String?], [Objects.ShopFairShopShopFairCategory?]?>

tzdesign avatar Feb 12 '24 12:02 tzdesign