Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test to ensure defer/stream payloads are always sent in correct order #3165

Closed
wants to merge 15 commits into from

Conversation

yaacovCR
Copy link
Contributor

@yaacovCR yaacovCR commented Jun 7, 2021

currently failing @robrichard @brainkim

robrichard and others added 11 commits June 4, 2021 11:10
Support returning async iterables from resolver functions
# Conflicts:
#	src/index.d.ts
#	src/type/directives.d.ts
#	src/type/directives.ts
#	src/type/index.js
# Conflicts:
#	src/index.d.ts
#	src/type/directives.d.ts
#	src/type/directives.ts
#	src/type/index.js
# Conflicts:
#	src/execution/execute.ts
#	src/validation/index.d.ts
#	src/validation/index.ts
# Conflicts:
#	src/subscription/subscribe.ts
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jun 7, 2021

Now passing, with some changes in payload order, and in execution algorithm, namely completion does not start for any streamed item until completion for the prior item finishes.

This is suboptimal. What we want is for completion to start for all possible items as soon as possible, but for payload order to still be preserved. Or -- perhaps, we want to relax the requirement in the spec for all items to be sent in sequential order?

@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jun 7, 2021

Note that the failing check has to do with uploading code-coverage and appears--at least to me--to be orthogonal to the changes here.

@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jun 8, 2021

see discussion at #2848 (which perhaps should be moved here?)

I have reverted the "fix" for now as I am not sure it is the desirable behavior. Perhaps we should "fix" the tests to reflect the current implementation.

@yaacovCR yaacovCR changed the title add test to ensure stream payloads are always sent in correct order Jul 3, 2021
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jul 3, 2021

I added additional tests for stream payloads that are asyncIterables, defer payloads, and defer/stream payload interactions, as I understood from recent WG notes that we want to enforce order for both defer/stream payloads by default, and occurred to me that this "bug" may be more far-reaching, include defer fragments, etc.

Personally, I am agnostic to what the desired behavior should be, at this point tending more toward @robrichard that we should just send what we have, when we have it.

Although I am sensitive to @benjie 's point about malicious servers, I think that we can push onto clients to handle that situation less naively.

@benjie
Copy link
Member

benjie commented Jul 5, 2021

Although I am sensitive to @benjie 's point about malicious servers, I think that we can push onto clients to handle that situation less naively.

I would like to caution against pushing requirements onto the client without sufficiently evaluating the alternatives, primarily because there's a lot more GraphQL clients than there are GraphQL servers (e.g. there's a bunch that people roll their own using e.g. window.fetch(...)). Demanding that every one of these GraphQL clients factors in subtle intricacies in the defer/stream protocol is a big ask. When it goes wrong, some people aren't going to think "Oh I implemented that wrong" but rather "Why is GraphQL giving me payloads out of order? That seems like a bug..."

@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jul 7, 2021

I agree there is validity to architecting toward the simplest possible behavior in the hopes of not being blamed then things go “wrong.”

But I also think we should be thinking primarily about use cases. Might it make sense to display data from a deferred User Profile fragment when it’s ready even when the complete User fragment higher up in the tree has not yet come in? I think that would really be the clients choice. Would it make sense to give client data from a later list item as soon as available, “leaking” as well the knowledge that they are X intervening items? I think it would.

I am envisioning basically the overarching goal of incremental delivery being to provide overall speediest delivery.

GraphQL lists always have a defacto order when resolved and so they can be thought of as a map with numeric keys.

Overall agree with argument approach to dictate this, but I feel like the default behavior should be to optimize for fastest delivery, not for easiest client implementation.

But I wouldn’t put my own preference on a pedestal. I will be working on an stitching implementation that will eventually probably have to handle both, whether by default or by argument, so I probably have to just start out not making assumptions about the order���

@robrichard robrichard force-pushed the defer-stream branch 3 times, most recently from c98de06 to a09e09c Compare August 30, 2021 16:23
@IvanGoncharov IvanGoncharov added the spec RFC Implementation of a proposed change to the GraphQL specification label Oct 23, 2021
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Dec 7, 2021

Closed as fixed here and in graphql-executor

@yaacovCR yaacovCR closed this Dec 7, 2021
@yaacovCR yaacovCR deleted the test-order branch March 21, 2022 15:15
@yaacovCR yaacovCR restored the test-order branch March 21, 2022 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec RFC Implementation of a proposed change to the GraphQL specification
6 participants