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 support for multipart subscriptions #3076

Merged
merged 68 commits into from
Aug 31, 2024
Merged

Add support for multipart subscriptions #3076

merged 68 commits into from
Aug 31, 2024

Conversation

patrick91
Copy link
Member

@patrick91 patrick91 commented Sep 6, 2023

This is a new protocol created by Apollo (and supported by Apollo Client)

TODO

  • Add support for this in all HTTP integrations that support subscriptions
  • Send a ping every 5 seconds (an empty {} is enough)
  • Add a proper way to check if an operation is a subscription in our Async HTTP View
  • Make sure that the returned responses is actually being streamed
  • Return proper error when trying to run a subscription and it's not supported
  • Add docs (using a proxy breaks the disconnection)

Protocol docs: https://www.apollographql.com/docs/router/executing-operations/subscription-multipart-protocol/

strawberry/http/async_base_view.py Outdated Show resolved Hide resolved
strawberry/http/async_base_view.py Outdated Show resolved Hide resolved
strawberry/http/async_base_view.py Show resolved Hide resolved
tests/views/schema.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

Attention: Patch coverage is 91.42857% with 21 lines in your changes missing coverage. Please review.

Project coverage is 96.79%. Comparing base (08db7f7) to head (20e8bf7).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3076      +/-   ##
==========================================
- Coverage   96.82%   96.79%   -0.04%     
==========================================
  Files         514      517       +3     
  Lines       33322    33528     +206     
  Branches     5528     5575      +47     
==========================================
+ Hits        32263    32452     +189     
- Misses        835      847      +12     
- Partials      224      229       +5     

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 6, 2023

CodSpeed Performance Report

Merging #3076 will degrade performances by 28.11%

Comparing feature/multipart (20e8bf7) with main (08db7f7)

Summary

❌ 1 regressions
✅ 14 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main feature/multipart Change
test_execute 589.2 ms 819.6 ms -28.11%

@github-actions
Copy link

Hi 👋 You can find a preview of the docs here:

https://strawberry.rocks/docs/pr/3076/integrations/index

@patrick91
Copy link
Member Author

patrick91 commented Oct 15, 2023

~~one thing I'm not sure about this is handling client closing the connections 🤔 ~~

edit: this seems to be handled by fastapi, I need to check django and others, also I was using next.js' proxy for this, and that was preventing the disconnect message from being sent

@patrick91 patrick91 merged commit 68296e0 into main Aug 31, 2024
12 checks passed
@patrick91 patrick91 deleted the feature/multipart branch August 31, 2024 11:11
@patrick91
Copy link
Member Author

🔥

Comment on lines +131 to +138
return await subscribe( # type: ignore
schema,
execution_context.graphql_document,
root_value=execution_context.root_value,
context_value=execution_context.context,
variable_values=execution_context.variables,
operation_name=execution_context.operation_name,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extends the Schema.execute method to handle subscriptions. Im wondering whether this was intentional since we already have a separate Schema.subscribe method? 👀 @patrick91 @bellini666

I noticed this change while upgrading to the latest version. In my codebase mypy now complains everywhere that Schema.execute can now return both ExecutionResult and SubscriptionExecutionResult. Before Schema.execute could only return an ExecutionResult while subscriptions were handled by Schema.subscribe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was poor design on my part, it will be fixed in #3554 😊

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.

5 participants