Skip to content

allow for directives to be added to the types #204

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

Merged
merged 8 commits into from
Apr 25, 2025

Conversation

csechrist
Copy link
Contributor

@csechrist csechrist commented Oct 20, 2024

Description

Allow for directives to be added to the SQLAlchemy type mapper. This enables us to use it with GraphQL federation more effectively

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

Summary by Sourcery

Enhance the SQLAlchemy type mapper to support directives, facilitating better integration with GraphQL federation, and update pre-commit hooks to their latest versions.

Enhancements:

  • Add support for directives in the SQLAlchemy type mapper to improve compatibility with GraphQL federation.

Build:

  • Update pre-commit hooks to newer versions, including black, ruff, prettier, pre-commit-hooks, and blacken-docs.

Copy link
Contributor

sourcery-ai bot commented Oct 20, 2024

Reviewer's Guide by Sourcery

This pull request enhances the SQLAlchemy type mapper to allow for the addition of directives, improving its compatibility with GraphQL federation. The changes primarily affect the mapper.py file, with updates to the type decorator and convert method. Additionally, the PR updates several dependencies in the .pre-commit-config.yaml file.

Updated class diagram for SQLAlchemy type mapper

classDiagram
    class Mapper {
        +type(model: Type[BaseModelType], make_interface: bool, use_federation: bool, directives: Union[Sequence[object], None] = ())
        +convert(type_: Any) Any
    }
    note for Mapper "The 'type' method now accepts 'directives' to enhance GraphQL federation compatibility."
Loading

File-Level Changes

Change Details Files
Add support for directives in the SQLAlchemy type mapper
  • Introduce a new 'directives' parameter in the 'type' decorator
  • Modify the 'convert' method to include directives when creating strawberry types
  • Update the federation type creation to include directives
src/strawberry_sqlalchemy_mapper/mapper.py
Update pre-commit hook dependencies
  • Update black from 23.9.1 to 24.10.0
  • Update ruff from v0.0.289 to v0.7.0
  • Update prettier from v3.0.3 to v4.0.0-alpha.8
  • Update pre-commit-hooks from v4.4.0 to v5.0.0
  • Update blacken-docs from 1.16.0 to 1.19.0
.pre-commit-config.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@botberry
Copy link
Member

botberry commented Oct 20, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Added support for GraphQL directives in the SQLAlchemy type mapper, enabling better integration with GraphQL federation.

Example usage:

@mapper.type(Employee, directives=["@deprecated(reason: 'Use newEmployee instead')"])
class Employee:
    pass

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @csechrist - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding documentation for the new 'directives' parameter in the type mapping function. This will help users understand how to utilize this new feature effectively.
  • Please review and update the PR checklist. Ensuring all applicable items are checked will help maintain the project's quality standards.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@Ckk3 Ckk3 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 for your contribution! I've reviewed your code and left one comment, please take a look when you can.

Additionally, it would be great if you could create new tests to ensure this solution remains stable in future updates.

I also believe this change needs to be added on our documentation. While I know our docs aren't perfect, adding a note to the README in Markdown will works for now. I think it could go right before the Limitations section, what do you think?

Thanks again!

@Ckk3 Ckk3 self-assigned this Oct 22, 2024
@csechrist
Copy link
Contributor Author

Sounds great! I will get tests added in and get the documentation updated this week!

@Ckk3
Copy link
Contributor

Ckk3 commented Nov 12, 2024

Hi, @csechrist , any updates?

@Ckk3 Ckk3 removed their assignment Feb 25, 2025
@Ckk3 Ckk3 self-assigned this Apr 24, 2025
@Ckk3
Copy link
Contributor

Ckk3 commented Apr 24, 2025

I pick up this PR and create new tests!

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 86.05%. Comparing base (9f98569) to head (3e3a6a0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #204      +/-   ##
==========================================
+ Coverage   85.51%   86.05%   +0.54%     
==========================================
  Files          16       16              
  Lines        1629     1671      +42     
  Branches      139      136       -3     
==========================================
+ Hits         1393     1438      +45     
- Misses        173      174       +1     
+ Partials       63       59       -4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

codspeed-hq bot commented Apr 24, 2025

CodSpeed Performance Report

Merging #204 will not alter performance

Comparing csechrist:main (3e3a6a0) with main (9f98569)

Summary

✅ 1 untouched benchmarks

@Ckk3
Copy link
Contributor

Ckk3 commented Apr 24, 2025

@bellini666 @fruitymedley @patrick91 @erikwrede
Please take a look when you can, I created the tests to this one!

@Ckk3 Ckk3 merged commit fbdfa54 into strawberry-graphql:main Apr 25, 2025
19 checks passed
@botberry
Copy link
Member

Thanks for contributing to Strawberry! 🎉 You've been invited to join
the Strawberry GraphQL organisation 😊

You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67

And don't forget to join our discord server: https://strawberry.rocks/discord 🔥

@Ckk3
Copy link
Contributor

Ckk3 commented Apr 25, 2025

Thank you so much, @csechrist ❤️

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.

5 participants