-
-
Notifications
You must be signed in to change notification settings - Fork 544
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 support for @stream
and @defer
#3402
Comments
@patrick91 i wondered if you have a list of the requirements of what would be needed to add defer and stream support into strawberry. Or any idea how complex this is to implement. It’s probably our next big performance win. So mulling over / investigating how hard it would be to make this happen, either through committing resources or funding for it. |
@matclayton we have a few bits in places already, but we need support from GraphQL-core first, unless you're ok with using an alpha 😊 |
I think we might be running it already, our coverage here is pretty good, so not too concerned about that! Ive been following the alpha closely for a while and kinda assuming it would have shipped already. |
@matclayton I think they are waiting for GraphQL.js to ship a stable release of defer 😊 |
Reasonable, we're on Relay 18.2.0 which has lots of nice defer based features :) |
@matclayton I see, I think an on-going sponsorship would help us with getting this shipped 😊 I'm a bit worried about things changing in future version of GraphQL-core and GraphQL.js |
Lets grab a chat and see what that would entail, I'd love to find a way to make that work, just not sure how. do you have my email? |
@matclayton yes, I'll send you a message :) |
Yesterday I was playing around with implementing support for
@stream
(and indirectly, for@defer
)Firstly, the work will be based on #3076, since it adds quite all the fundamentals we need for delivering incremental updates (the Multipart Subscription protocol is very similar to what we need for
@stream
and@defer
). We'd probably need some refactoring, but the base is there :)@stream
,strawberry.Streamable
, AsyncGenerator and listsIn GraphQL,
@stream
can only be used on fields that return a list of items, meanwhile in Python we need to use anAsyncGenerator
to enable streaming, this is how a simple resolver would look like:We are already using
AsyncGenerator
for subscription (and in subscription you don't need to use lists for values), so I thought of introducing a new type (which is just an alias toAsyncGenerator
):strawberry.Streamable
The usage would look like this:
when using
strawberry.Streamable[X]
, Strawberry knows to convert this to a list ofX
, so the GraphQL schema will be correct.My only issue with this is that we are hiding the fact that count is a list in GraphQL, but I think it is worth the tradeoff, especially because we can't really do much else while keeping the typing working fine.
And having a dedicated type could allow us to raise proper errors when using
@stream
with lists that are not actually streamable (I don't think it would make sense in that case, no?)What do you all think?
Upvote & Fund
The text was updated successfully, but these errors were encountered: