Skip to content

(feat) cli: export schema from callable#3797

Merged
patrick91 merged 1 commit into
strawberry-graphql:mainfrom
alexey-pelykh:feat/cli-schema-from-callable
Mar 4, 2025
Merged

(feat) cli: export schema from callable#3797
patrick91 merged 1 commit into
strawberry-graphql:mainfrom
alexey-pelykh:feat/cli-schema-from-callable

Conversation

@alexey-pelykh

@alexey-pelykh alexey-pelykh commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

Description

Add support for exporting schema created by a callable:

strawberry export-schema package.module:create_schema

when

def create_schema():
    return strawberry.Schema(query=Query)

Types of Changes

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

Issues Fixed or Closed by This PR

None that I'm aware of

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

Adds support for exporting a schema created by a callable function using the command line interface.

New Features:

  • Adds support for exporting schema created by a callable via the command line interface.

Tests:

  • Adds a test case to verify that the CLI can export a schema when the schema symbol is a callable.

@sourcery-ai

sourcery-ai Bot commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

Reviewer's Guide by Sourcery

This pull request introduces the ability to export a Strawberry schema from a callable function using the strawberry export-schema command. The changes include modifications to the CLI utilities to handle callable schema symbols, updates to the documentation, and the addition of a new test case to ensure the new functionality works as expected.

Sequence diagram for exporting schema from callable

sequenceDiagram
  participant CLI
  participant utils
  participant Module
  participant Schema

  CLI->>utils: load_schema(schema_string, app_dir)
  utils->>Module: Import schema_symbol from schema_string
  alt schema_symbol is callable
    Module->>Module: schema_symbol()
  end
  Module-->>utils: schema_symbol (Schema)
  utils->>Schema: isinstance(schema_symbol, Schema)
  alt not isinstance(schema_symbol, Schema)
    utils->>CLI: Error: schema must be an instance of strawberry.Schema
  else
    utils-->>CLI: Schema
  end
Loading

File-Level Changes

Change Details Files
Added support for exporting a schema created by a callable function.
  • Updated the export-schema command to accept a callable that returns a strawberry.Schema.
  • If the loaded schema symbol is callable, it will be called to get the schema instance.
strawberry/cli/utils/__init__.py
Updated documentation to reflect the new functionality.
  • Updated the schema-export.md guide to mention that the schema symbol can be a callable.
  • Added a RELEASE.md file to describe the new feature.
docs/guides/schema-export.md
RELEASE.md
Added a test case to verify that the schema symbol can be a callable.
  • Added a new test case test_schema_symbol_is_callable to test_export_schema.py.
  • Added a create_schema function to sample_module.py to be used in the new test case.
tests/cli/test_export_schema.py
tests/fixtures/sample_package/sample_module.py

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Overall Comments:

  • Consider adding a test case with a more complex callable, perhaps one with arguments.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 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.

Comment thread strawberry/cli/utils/__init__.py Outdated
Comment thread tests/cli/test_export_schema.py
Comment thread tests/cli/test_export_schema.py
@botberry

botberry commented Mar 4, 2025

Copy link
Copy Markdown
Member

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release adds support for exporting schema created by a callable:

strawberry export-schema package.module:create_schema

when

def create_schema():
    return strawberry.Schema(query=Query)

Here's the tweet text:

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

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

@botberry

botberry commented Mar 4, 2025

Copy link
Copy Markdown
Member

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release adds support for exporting schema created by a callable:

strawberry export-schema package.module:create_schema

when

def create_schema():
    return strawberry.Schema(query=Query)

Here's the tweet text:

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

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

@alexey-pelykh alexey-pelykh force-pushed the feat/cli-schema-from-callable branch from f217d3d to 765e81e Compare March 4, 2025 12:30
@codecov

codecov Bot commented Mar 4, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.

Project coverage is 97.23%. Comparing base (80a5d14) to head (765e81e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3797      +/-   ##
==========================================
- Coverage   97.24%   97.23%   -0.02%     
==========================================
  Files         503      503              
  Lines       33568    33581      +13     
  Branches     1717     1718       +1     
==========================================
+ Hits        32642    32651       +9     
- Misses        707      711       +4     
  Partials      219      219              

@codspeed-hq

codspeed-hq Bot commented Mar 4, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #3797 will not alter performance

Comparing alexey-pelykh:feat/cli-schema-from-callable (765e81e) with main (80a5d14)

Summary

✅ 21 untouched benchmarks

@patrick91 patrick91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!

@patrick91 patrick91 merged commit 3659e1f into strawberry-graphql:main Mar 4, 2025
@alexey-pelykh alexey-pelykh deleted the feat/cli-schema-from-callable branch March 4, 2025 14:54
amlimaye pushed a commit to Tyba-Energy/strawberry that referenced this pull request Mar 31, 2025
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.

3 participants