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

feature: map sqlalchemy doc attribute to strawberry fields #203

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

Conversation

YovelB98
Copy link

@YovelB98 YovelB98 commented Oct 18, 2024

Description

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

Introduce a feature to map SQLAlchemy column 'doc' attributes to Strawberry field descriptions, enhancing the integration between SQLAlchemy and Strawberry GraphQL. Update tests to ensure this mapping works correctly and document the change in the release notes.

New Features:

  • Map SQLAlchemy column 'doc' attribute to Strawberry field descriptions.

Documentation:

  • Document the new behavior of mapping SQLAlchemy 'doc' attributes to Strawberry field descriptions in the release notes.

Tests:

  • Add tests to verify that SQLAlchemy 'doc' attributes are correctly mapped to Strawberry field descriptions.

Copy link
Contributor

sourcery-ai bot commented Oct 18, 2024

Reviewer's Guide by Sourcery

This pull request adds support for mapping SQLAlchemy doc attributes to Strawberry fields' descriptions. It also introduces the ability to set a description for the entire Strawberry type. These changes enhance the generated GraphQL schema by providing more detailed information about types and fields.

Updated class diagram for the mapper class

classDiagram
    class Mapper {
        +_add_annotation(type_: Any, key: str, annotation: Any, generated_field_keys: List[str], field_description: str = None)
        +type(model: Type[BaseModelType], make_interface: bool = false, use_federation: bool = false, description: str = None) -> Callable[[Type[object]], Any]
    }
    note for Mapper "Added field_description parameter to _add_annotation and description parameter to type method"
Loading

File-Level Changes

Change Details Files
Added support for mapping SQLAlchemy doc attributes to Strawberry field descriptions
  • Modified the _add_annotation method to accept a field_description parameter
  • Updated the _handle_columns method to pass the column.doc as field_description
  • Added a new test case to verify the mapping of SQLAlchemy doc to Strawberry field description
src/strawberry_sqlalchemy_mapper/mapper.py
tests/test_mapper.py
Implemented support for setting a description for the entire Strawberry type
  • Added a description parameter to the type decorator method
  • Updated the type conversion logic to pass the description to strawberry.type, strawberry.interface, and strawberry.federation.type
src/strawberry_sqlalchemy_mapper/mapper.py
Added a new test case to verify the new description mapping functionality
  • Created a test_mapper_support_description function to check both type and field description mapping
tests/test_mapper.py
Updated the employee table in the test setup
  • Added a doc attribute to the name column in the Employee model
tests/test_mapper.py
Added a RELEASE.md file
  • Created a new file to document the release type and changes
RELEASE.md

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 18, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Adding a new behavior where the mapper supports the SQLAlchemy doc=XXX
to be shown as the description of the fields generated in the GQL schema later on.

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 @YovelB98 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 2 issues found

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.

tests/test_mapper.py Show resolved Hide resolved
RELEASE.md Outdated Show resolved Hide resolved
RELEASE.md Outdated Show resolved Hide resolved
@YovelB98
Copy link
Author

@patrick91 @bellini666 May you please have a look on this one when you have time? Pretty small feature/fix that benefits great value

Copy link
Member

@erikwrede erikwrede left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the PR! I'd prefer us to make this configurable. While some use cases of this library are very close to the database schema, including docstrings, we'd want to avoid a situation that accidentally exposes internal docs, especially for existing solutions. This is in line with the decision we've taken over at the core strawberry library. Once we have some confogurability, I'm positive we could make this a feature.

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.

3 participants