strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
MIT License
393 stars 115 forks source link

Docs improvement Subscriptions #376

Closed sdobbelaere closed 9 months ago

sdobbelaere commented 9 months ago

As referred to in issue #375 some improved guidance on getting subscriptions running including the missing pieces related to the test-server.

codecov-commenter commented 9 months ago

Codecov Report

Attention: 27 lines in your changes are missing coverage. Please review.

Comparison is base (c15a66e) 88.00% compared to head (1bcbb67) 87.39%. Report is 6 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #376 +/- ## ========================================== - Coverage 88.00% 87.39% -0.61% ========================================== Files 33 35 +2 Lines 2976 3023 +47 ========================================== + Hits 2619 2642 +23 - Misses 357 381 +24 ``` | [Files](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/376?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql) | Coverage Δ | | |---|---|---| | [strawberry\_django/auth/queries.py](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/376?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql#diff-c3RyYXdiZXJyeV9kamFuZ28vYXV0aC9xdWVyaWVzLnB5) | `100.00% <100.00%> (ø)` | | | [strawberry\_django/middlewares/debug\_toolbar.py](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/376?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql#diff-c3RyYXdiZXJyeV9kamFuZ28vbWlkZGxld2FyZXMvZGVidWdfdG9vbGJhci5weQ==) | `58.33% <100.00%> (+0.35%)` | :arrow_up: | | [strawberry\_django/permissions.py](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/376?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql#diff-c3RyYXdiZXJyeV9kamFuZ28vcGVybWlzc2lvbnMucHk=) | `79.81% <71.42%> (-0.31%)` | :arrow_down: | | [strawberry\_django/auth/utils.py](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/376?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql#diff-c3RyYXdiZXJyeV9kamFuZ28vYXV0aC91dGlscy5weQ==) | `63.15% <63.15%> (ø)` | | | [strawberry\_django/routers.py](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/376?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql#diff-c3RyYXdiZXJyeV9kamFuZ28vcm91dGVycy5weQ==) | `0.00% <0.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sdobbelaere commented 9 months ago
bellini666 commented 9 months ago

@sdobbelaere I just solved the remaining pyright issues for you.

If the tests are passing fine, is there anything else missing from this or can it be merged?

sdobbelaere commented 9 months ago

@sdobbelaere I just solved the remaining pyright issues for you.

If the tests are passing fine, is there anything else missing from this or can it be merged?

Thank you for the help, much appreciated. The only thing left is commit b0a464a455afe3ca3f6fd27048d0e12a5c5c7a08 which allows you to manually set a user in the context for testing, on the condition that you mark it as "is_test_mode".

Why did I add this? Running tests needs access to a user in my case, this allows to construct a simple context when running tests like so:

from django.contrib.auth import get_user_model
from MyProject.schemas import schema

user = get_user_model().objects.last()
dummy_context = {'is_test_mode': True, 'user': user}

resp = schema.execute_sync(query=query, context_value=dummy_context)

Happy to add it to the docs.

bellini666 commented 9 months ago

@sdobbelaere I just solved the remaining pyright issues for you. If the tests are passing fine, is there anything else missing from this or can it be merged?

Thank you for the help, much appreciated. The only thing left is commit b0a464a which allows you to manually set a user in the context for testing, on the condition that you mark it as "is_test_mode".

Why did I add this? Running tests needs access to a user in my case, this allows to construct a simple context when running tests like so:

from django.contrib.auth import get_user_model
from MyProject.schemas import schema

user = get_user_model().objects.last()
dummy_context = {'is_test_mode': True, 'user': user}

resp = schema.execute_sync(query=query, context_value=dummy_context)

Happy to add it to the docs.

As I mentioned there, I don't like that approach very much, specially because we have a way for forcing a user into the request: https://github.com/strawberry-graphql/strawberry-graphql-django/blob/main/strawberry_django/test/client.py#L75

You can see it being used in here for example: https://github.com/strawberry-graphql/strawberry-graphql-django/blob/main/tests/test_permissions.py#L49

sdobbelaere commented 9 months ago

Just a small nitpick and it should be good to merge :)

Thanks for taking the time to adjust everything I asked

yw :)