You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scenario to reproduce:
Client requests first 3 edges of relay list of list total length 4 at time t.
At time t+1,
underlying list is mutated at data source, list becomes 2 items shorter.
Length of edge list is now 2, but GraphQL client thinks list is length 4.
At time t+2,
Client requests some more edges specifying parameter after as 3
java.lang.IllegalArgumentException: fromIndex(3) > toIndex(2)
at java.util.ArrayList.subListRangeCheck(ArrayList.java:1006)
at java.util.ArrayList.subList(ArrayList.java:996)
at graphql.relay.SimpleListConnection.get(SimpleListConnection.java:42)
at GraphQL.DataFetchers.lambda$getPlaylistGroupVideosDataFetcher$20(DataFetchers.java:365)
at graphql.execution.ExecutionStrategy.resolveField(ExecutionStrategy.java:46)
at graphql.execution.SimpleExecutionStrategy.execute(SimpleExecutionStrategy.java:18)
at graphql.execution.ExecutionStrategy.completeValue(ExecutionStrategy.java:92)
at graphql.execution.ExecutionStrategy.resolveField(ExecutionStrategy.java:52)
at graphql.execution.SimpleExecutionStrategy.execute(SimpleExecutionStrategy.java:18)
at graphql.execution.Execution.executeOperation(Execution.java:69)
at graphql.execution.Execution.execute(Execution.java:42)
at graphql.GraphQL.execute(GraphQL.java:78)
at graphql.GraphQL.execute(GraphQL.java:55)
dalenavi
changed the title
Check for invalid list indices on client-provided cursor
Check for invalid SimpleListConnection list indices on client-provided cursor
Mar 21, 2016
Thanks for this PR!
Is this case specified somewhere (by Relay) how this should be handled? I mean is this even "legal" that the number of edges is changed?
By the spec, 'before' or 'after' should be a cursor type, an opaque node ID, a string. Not an array index.
To enable forward pagination, two arguments are required.
* first takes an integer.
* after takes the cursor type as described in the cursor field section.
An “Edge Type” must contain a field called cursor. This field must return a type that serializes as a String
...
Whatever type this field returns will be referred to as the cursor type in the rest of this spec.
Let afterEdge be the edge in edges whose cursor is equal to the after argument.
If afterEdge exists:
Remove all elements of edges before and including afterEdge.
I think I'm off track with the above references...
I had the impression the spec suggested using a node id as the cursor.
Maybe using the array offset as cursor is also a valid cursor type.
I see now the array index cursor is still encoded as an opaque node id...
Doesn't really change the question though.
If a client is requesting some List resource using Relay pagination,
and the underlying List changes between calls,
then this situation could occur.
What possible way to prevent it? Can't cache the list-as-it-was-when-first-requested indefinitely.
@dalenavi It took some time to merge it, but is is finally it. :-) Thanks
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
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.
Scenario to reproduce:
Client requests first 3 edges of relay list of list total length 4 at time t.
At time t+1,
underlying list is mutated at data source, list becomes 2 items shorter.
Length of edge list is now 2, but GraphQL client thinks list is length 4.
At time t+2,
Client requests some more edges specifying parameter
afteras 3