cynic icon indicating copy to clipboard operation
cynic copied to clipboard

Can we infer bounds on generic QueryFragments

Open obmarg opened this issue 2 years ago • 1 comments

#708 asked if it's possible to make the response type in a QueryFragment generic. It seems possible at the moment, but you have to specify bounds on the generic parameters (and the variable fields type - which is a bit unclear) to get it to work.

I'm wondering if it would be possible to add these bounds automatically... Needs some thought - my initial experiment suggests it would be possible, but there might be some downsides that need to be considered.

In particular we'd need to be careful to only add bounds for types that actually need them - seems like it would be possible to have a parameter that didn't need to be QueryFragment, so need to make sure we don't add bounds on those parameters.

obmarg avatar Jun 09 '23 20:06 obmarg

I think the logic for this is roughly:

  • Walk the struct definition looking to see which field(s) each generic parameter is used on.
  • Any field that is unambiguously some GraphQL schema type should get variable match & query fragment bounds added to the QueryFragment impl where clause.
    • Excluding fields that appear in conflicting positions in the struct.
    • Possibly excluding cases where we can't figure out the arity, or otherwise have difficulty being sure?

obmarg avatar Jan 09 '24 21:01 obmarg