Repository navigation
Fix paging on the node of another connection - #577
Merged
lukemurray merged 1 commit intoOct 10, 2026
Merged
lukemurray merged 1 commit into
lukemurray merged 1 commit into
Conversation
{ movies(first: 2) { edges { node { actors(first: 1) { ... } } } } } with
UseConnectionPaging (or UseOffsetPaging) on the inner field failed with
"unbound variable: p_ConnectionEdge`1", in memory and with EF.
- The inner edges/items field rebuilt its collection from the grandparent
node's NextFieldContext. For `node` that is the schema expression
p_ConnectionEdge.Node, not the edge being selected. Field.GetExpression
now records the context a field with extensions is bound to on the
(per-request) CompileContext, and the edges/items extensions use it.
- The edges field (and its ConnectionEdgeExtension) is shared by every
connection of a type, and its Select parameter was a field on the
extension. The same connection at two levels declared it in nested
lambdas, which EF can not rewrite ("When called from 'VisitLambda'...").
Create it per use.
EF still needs SQL APPLY to page a nested collection inside another paged
nested collection, which SQLite does not support - the two-level case is
tested in memory with a check that no lambda shadows a parameter.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
lukemurray
force-pushed
the
fix/connection-in-connection-node
branch
from
October 10, 2026 18:56
b5e1542 to
c631041
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #576. This PR's base is that branch, so GitHub will retarget it to
mainonce #576 merges.Problem
Paging on the
nodeof another connection failed in memory and with EF, onmainas well:{ movies(first: 2) { edges { node { name actors(first: 1) { edges { node { name } } } } } } }UseOffsetPaging()on the inner field failed the same way.Cause and fix
ConnectionEdgeExtensionandOffsetPagingItemsExtensionrebuild the collection from the paging field's original expression. They bound it to the grandparent node'sNextFieldContext. For a parent that is a list or a root field, that's the context the field was compiled against. Fornode, it's the schema expressionp_ConnectionEdge.Node, not the edge being selected, so the parameter is left unbound. Extensions are given the field's own expression asContext. SoField.GetExpressionnow records the context a field with extensions is bound to on the per-requestCompileContext(aninternalstore, so no new public API). The edges/items extensions use that and fall back to the old lookup.ConnectionEdgeExtension). ItsSelectparameteredgeNodewas a field on the extension. With the same connection field at two levels (actor.movies ... actors.node.movies), nested lambdas declared the sameParameterExpression. That compiles in memory, but EF fails withWhen called from 'VisitLambda', rewriting a node of type 'ParameterExpression' must return a non-null value of the same type. The parameter is now created per use and read back from theSelectwhen the selection is rebuilt.Provider note
To page a nested collection inside another paged nested collection, EF needs SQL
APPLY. SQLite doesn't support it, so on SQLite that query fails with EF'sTranslating this query requires the SQL APPLY operation. I checked the same three query shapes against the SQL Server provider (with a server that doesn't exist): they translate, and the only errors were connection failures. That covers translation only, not results against a real database.Tests
ConnectionPagingTests.TestPagingInConnectionNode(in memory): a connection and an offset-paged field on thenodeof a root connection, checking values, cursors and counts.PagingTests.TestNestedConnectionPagingInConnectionNode(EF/SQLite): a navigation connection on thenodeof a rootIQueryableconnection, usinglastat both levels.PagingTests.TestNestedConnectionPagingSameFieldAtTwoLevels(in memory, see the provider note): three levels withActor.moviesused twice, checking results. It also walks the compiled expression and asserts that no lambda re-declares an enclosing lambda's parameter. With the shared parameter put back temporarily, this check failed as expected.Full suite passes on net8.0, net9.0 and net10.0.
🤖 Generated with Claude Code