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

Fix GraphQL tests failing when executed alongside all tests #310

Closed
tjeerddie opened this issue Jul 20, 2023 · 0 comments
Closed

Fix GraphQL tests failing when executed alongside all tests #310

tjeerddie opened this issue Jul 20, 2023 · 0 comments
Labels
enhancement Enhancement or extension of existing feature

Comments

@tjeerddie
Copy link
Contributor

tjeerddie commented Jul 20, 2023

Recently, we introduced GraphQL some tests as a separate step in the unit test GitHub action due to their failure when run alongside other tests. This issue is to look for a way to fix this.

When running the GraphQL test along with other tests, an error is encountered: The type "<class 'test.unit_tests.fixtures.products.product_blocks.product_sub_block_two.test_product_sub_block_two.<locals>.SubBlockTwoForTestInactive'>" cannot be resolved for the field "listUnionBlocks" , are you using a strawberry.field.

Reference: Link to the pull request discussion

I suspected that the reason for these GraphQL tests failing is that the product model classes are contained within fixtures and are re-created in every test. On the other hand, GraphQL is registered once as part of a session fixture, which auto-generates all models in SUBSCRIPTION_MODEL_REGISTRY during that time. As a result, only the first test has the original models, while any subsequent tests receive re-created classes.

@tjeerddie tjeerddie added the enhancement Enhancement or extension of existing feature label Jul 20, 2023
tjeerddie added a commit that referenced this issue Jan 16, 2024
- change unit test github action to not run graphql separately
- update override_class function typing.

Fixes: #393, #310
tjeerddie added a commit that referenced this issue Jan 16, 2024
- change unit test github action to not run graphql separately
- update override_class function typing.

Fixes: #393, #310
tjeerddie added a commit that referenced this issue Jan 16, 2024
* Improve ability to override existing graphql models.

- add strawberry class override to change field resolvers of existing classes.
- add unit tests for override_class function and add test that overrides `Query`.
- move register_domain_models to create_graphql_router.
- change register_domain_models to take existing models with a parameter instead of a global dict.
- move `StrawberryPydanticModel`, `StrawberryModelType` and `GRAPHQL_MODELS` to graphql.schemas init.
- create default `Subscription` inside the create_graphql_router to recreate it when interface is updated.

* Improve create_strawberry_enums

Co-authored-by: Mark Moes <mark_moes@live.nl>

* Change register_domain_models to not update GRAPHQL_MODELS

- rename format_default_subscriptions to format_base_subscription.
- improve test_override_class.

* Fix override tests that used incorrect detailed subscription

- move `create_subscription_strawberry_type` out of `add_class_to_strawberry`.

* Change override_class to take a list of strawberry fields

- the override_class can make the mapping itself instead of needing to do duplicate naming in the field and in the mapping given to the override_class.
- change interface type in autoregistration to Type.

* Change graphql subscription detail tests to not run separate

- change unit test github action to not run graphql separately
- update override_class function typing.

Fixes: #393, #310

* Bumpversion to 2.0.1rc1

---------

Co-authored-by: Mark Moes <mark_moes@live.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement or extension of existing feature
Projects
None yet
Development

No branches or pull requests

1 participant