Skip to content

Fix [UseConnection] source generation for resolvers returning Connection<T> - #10118

Open
PHILLIPS71 wants to merge 3 commits into
ChilliCream:mainfrom
PHILLIPS71:jp/source-gen-useconnection-generic-connection
Open

Fix [UseConnection] source generation for resolvers returning Connection<T>#10118
PHILLIPS71 wants to merge 3 commits into
ChilliCream:mainfrom
PHILLIPS71:jp/source-gen-useconnection-generic-connection

Conversation

@PHILLIPS71

Copy link
Copy Markdown
Contributor

[UseConnection] on a source generated resolver only worked for PageConnection<T>. Returning Task<Connection<T>> (the type the common DataLoader pattern ToConnectionAsync() produces) was broken two different ways:

  1. The generator did not recognize Connection<T> as a connection, because IsConnectionType only matched types deriving from ConnectionBase<,,>. The field ended up typed as a plain list with no paging arguments.

  2. Once recognized, the generator built the connection type by reflecting over Connection<T>'s public members. That produced code that does not compile (a bogus resolver for Accept(IPageObserver)) and the wrong schema shape: no nodes field, info instead of pageInfo, and an edge type missing cursor (interface base members aren't reachable through BaseType).

Fix

Mirror the split the runtime already uses for [UsePaging]: a shared generic connection type for plain Connection<T>, reflection based named types only for custom classes.

  • IsConnectionType now matches IConnection<T> implementors, a superset of the old ConnectionBase<,,> check.
  • When a resolver returns exactly Connection<T> or IConnection<T>, ConnectionTypeTransformer skips type synthesis and the generated code binds the field to the existing shared runtime ConnectionType through a new helper, ConnectionTypeHelper.CreateConnectionTypeReference. This gives correct edges { cursor node }, nodes, pageInfo, and totalCount with no reflection over the connection class.
  • PageConnection<T> and custom connection classes keep the existing reflection path.
  • Reflection based synthesis now skips void returning methods, so custom subclasses of Connection<T> can't hit the Accept compile error either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant