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

Implement unions as annotated types #2840

Merged

Conversation

Ambro17
Copy link
Contributor

@Ambro17 Ambro17 commented Jun 11, 2023

Description

Replace strawberry.union direct usage with typing.Annotated for better type hints

  • Add test for warning over multiple args in tests/types/resolving/test_unions.py
  • Add tests for unions new api equivalent to those of the old api in tests/types/resolving/test_unions.py

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).

@codecov
Copy link

codecov bot commented Jun 11, 2023

Codecov Report

Merging #2840 (2f6c288) into main (3487d19) will decrease coverage by 0.41%.
The diff coverage is 86.90%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2840      +/-   ##
==========================================
- Coverage   96.37%   95.96%   -0.41%     
==========================================
  Files         207      207              
  Lines        8957     9028      +71     
  Branches     1646     1662      +16     
==========================================
+ Hits         8632     8664      +32     
- Misses        206      238      +32     
- Partials      119      126       +7     

@botberry
Copy link
Member

botberry commented Jun 11, 2023

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release adds support for declaring union types using typing.Annotated
instead of strawberry.union(name, types=...).

Code using the old syntax will continue to work, but it will trigger a
deprecation warning. Using Annotated will improve type checking and IDE support
especially when using pyright.

Before:

Animal = strawberry.union("Animal", (Cat, Dog))

After:

from typing import Annotated, Union

Animal = Annotated[Union[Cat, Dog], strawberry.union("Animal")]

Here's the preview release card for twitter:

Here's the tweet text:

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

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

Copy link
Member

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

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

Thank you so much! <3

I've left only one comment 😊

strawberry/annotation.py Show resolved Hide resolved
@Ambro17 Ambro17 force-pushed the implement-unions-as-annotated-types branch from ebbb837 to 9e2ff64 Compare June 14, 2023 20:25
patrick91 and others added 7 commits June 14, 2023 17:29
* Replace click with typer

* Fix dependencies

* Fix type

* Update test for pyinstrument

* Lock

* Use stdout instead of output

* Add release notes

* Workound failing tests

* Fix one more test
…ql#2227)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matt Gilson <mgilson@lat.ai>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
strawberry/annotation.py Outdated Show resolved Hide resolved
strawberry/annotation.py Outdated Show resolved Hide resolved
Ambro17 and others added 3 commits June 14, 2023 18:33
Co-authored-by: Patrick Arminio <patrick.arminio@gmail.com>
@patrick91
Copy link
Member

I've worked on this a bit more, I think it is almost ready to go, I want to improve the errors, but shouldn't take too long 😊

@patrick91
Copy link
Member

This should be ready now 😊

Copy link
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

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

My 2 cents :)

strawberry/annotation.py Outdated Show resolved Hide resolved
strawberry/union.py Outdated Show resolved Hide resolved
strawberry/union.py Outdated Show resolved Hide resolved
@patrick91
Copy link
Member

this is ready!

Copy link
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

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

No more suggestions, LGTM 👍🏼

@patrick91
Copy link
Member

@bellini666 let's merge yours first and then this one later today or tomorrow 😊

@patrick91 patrick91 merged commit a7a7c0d into strawberry-graphql:main Jun 28, 2023
39 of 41 checks passed
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

5 participants