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 usage with default and default_factory arguments #3333

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

devkral
Copy link
Contributor

@devkral devkral commented Jan 10, 2024

Description

Currently it is not always possible to use the default and default_factory argument on strawberry.field.
It fails randomly and especially on root Query
This PR fixes the issue.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@botberry
Copy link
Member

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Fix using strawberry with default or default_factory (dataclasses basics)

Here's the tweet text:

🆕 Release (next) is out! Thanks to Alexander for the PR 👏

Get it here 👉 https://beta.strawberry.rocks/release/(next)

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Merging #3333 (830a729) into main (ba65949) will decrease coverage by 0.02%.
The diff coverage is 84.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3333      +/-   ##
==========================================
- Coverage   96.62%   96.61%   -0.02%     
==========================================
  Files         485      485              
  Lines       30292    30316      +24     
  Branches     3746     3751       +5     
==========================================
+ Hits        29271    29291      +20     
- Misses        832      835       +3     
- Partials      189      190       +1     

Copy link

codspeed-hq bot commented Jan 10, 2024

CodSpeed Performance Report

Merging #3333 will not alter performance

Comparing devkral:fix/root_defaults (830a729) with main (ba65949)

Summary

✅ 12 untouched benchmarks

Comment on lines +596 to +604
result = schema.execute_sync(
"""
query TestQuery{
sub {
foo
}
}
"""
)
Copy link
Member

Choose a reason for hiding this comment

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

isn't this fixed by passing a root value to schema.execute? 😊

Copy link
Contributor Author

@devkral devkral Jan 10, 2024

Choose a reason for hiding this comment

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

sounds good. There should be a default root value in execute instead of None.

But this also happens on sub types. There should be an automatic initialization of root queries and co

Copy link
Member

Choose a reason for hiding this comment

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

I get you, but I think that would make us quite opinionated, and also we can't guess how all types will be instantiated, this would only work if types don't require any argument 😊

Copy link
Contributor Author

@devkral devkral Jan 10, 2024

Choose a reason for hiding this comment

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

This task isn't easy as you have to provide a mutation or query instance depending on the query to execute.

this is a big task, instead of the small quick and dirty fix

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.

None yet

3 participants