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 issue with LazyType/Enums and generics #1235

Merged
merged 8 commits into from
Sep 14, 2021

Conversation

BryceBeagle
Copy link
Member

@BryceBeagle BryceBeagle commented Sep 11, 2021

Description

Resolves #1104 and #1158. This was a fairly straight-forward fix. During creation of the dynamically-generated resolved generic type, we weren't getting the name from the LazyType/EnumDefinition properly.

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

botberry commented Sep 11, 2021

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Fix issues (#1158 and #1104) where Generics using LazyTypes
and Enums would not be properly resolved

These now function as expected:

Enum

T = TypeVar("T")

@strawberry.enum
class VehicleMake(Enum):
    FORD = 'ford'
    TOYOTA = 'toyota'
    HONDA = 'honda'

@strawberry.type
class GenericForEnum(Generic[T]):
    generic_slot: T

@strawberry.type
class SomeType:
    field: GenericForEnum[VehicleMake]

LazyType

another_file.py

@strawberry.type
class TypeFromAnotherFile:
    something: bool

this_file.py

T = TypeVar("T")

@strawberry.type
class GenericType(Generic[T]):
    item: T

@strawberry.type
class RealType:
    lazy: GenericType[LazyType["TypeFromAnotherFile", "another_file.py"]]

Here's the preview release card for twitter:

Here's the tweet text:

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

Get it here 👉 https://github.com/strawberry-graphql/strawberry/releases/tag/(next)

@codecov
Copy link

codecov bot commented Sep 11, 2021

Codecov Report

Merging #1235 (fbc48b6) into main (12c27e2) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1235      +/-   ##
==========================================
+ Coverage   97.63%   97.69%   +0.06%     
==========================================
  Files          88       88              
  Lines        3382     3388       +6     
  Branches      496      498       +2     
==========================================
+ Hits         3302     3310       +8     
+ Misses         44       43       -1     
+ Partials       36       35       -1     

@BryceBeagle
Copy link
Member Author

@patrick91, looks like the mypy plugin isn't ready for this.

tests/types/test_lazy_types.py: error: INTERNAL ERROR: maximum semantic analysis iteration count reached

@BryceBeagle BryceBeagle changed the title Fix issue with LazyType and generics Fix issue with LazyType/Enums and generics Sep 12, 2021
@BryceBeagle BryceBeagle linked an issue Sep 12, 2021 that may be closed by this pull request
@patrick91 patrick91 merged commit a5a7d43 into main Sep 14, 2021
@patrick91 patrick91 deleted the bugfix/1158-circular-lazy-type branch September 14, 2021 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

circular imports, Lazytype, Generics Generic input type broken from 0.69.0 onward
3 participants