strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

added ability to override federation version on export schema command

Open iotflowadmin opened this issue 1 year ago • 4 comments

Description

Added option for the export_schema command to override the output federation version. ussage example: strawberry export-schema --federation-version=2.5

This change ONLY effect "strawberry export-schema" command and is fully backword-compatible without any logic change.

This enhancement is required to be able to work with routers (like: wundergraph cosmo - which currently support federation version only up to 2.5, or to use in organizations that can't currently update the federation version support of the router)

Warning: Please use with caution!!

If the schema define directives that are not supported by the specified version (in the override parameter) the schema will still generate the output useing the value from the override, and may break at runtime.

Types of Changes

  • [ ] Core
  • [ ] Bugfix
  • [ ] New feature
  • [x] Enhancement/optimization
  • [ ] Documentation

Checklist

  • [x] My code follows the code style of this project.
  • [x] My change requires a change to the documentation.
  • [x] I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING document.
  • [x] I have added tests to cover my changes.
  • [x] I have tested the changes and verified that they work and don't break anything (as well as I can manage).

iotflowadmin avatar Nov 14 '24 19:11 iotflowadmin

Reviewer's Guide by Sourcery

This PR adds functionality to override the federation version when exporting a GraphQL schema using the export-schema command. The implementation modifies the schema directive URL during export and includes new test cases to verify the functionality.

Sequence diagram for export-schema command with federation version override

sequenceDiagram
    actor User
    participant CLI as CLI
    participant App as Application
    participant Schema as Schema

    User->>CLI: Run export-schema with --federation-version
    CLI->>App: Set federation_version_override
    App->>Schema: Modify schema directive URL
    Schema-->>App: Return modified schema
    App-->>CLI: Output schema
    CLI-->>User: Display schema with overridden federation version

Updated class diagram for ImportedFrom class

classDiagram
    class ImportedFrom {
        +String name
        +String url
        +__init__(**kwargs: Dict[str, Any])
    }
    note for ImportedFrom "Added logic to override URL based on federation_version_override"

File-Level Changes

Change Details Files
Added federation version override functionality to the export-schema command
  • Added new --federation-version command line option
  • Implemented version override logic in ImportedFrom class
  • Added federation version base URL constant
  • Added warning about version compatibility risks
strawberry/cli/commands/export_schema.py
strawberry/federation/schema_directives.py
Added test coverage for federation version override feature
  • Created new test case for federation version override
  • Added sample federated module for testing
  • Verified schema output with custom federation version
tests/cli/test_export_schema.py
tests/fixtures/sample_package/sample_module_federated.py
Updated documentation with new feature details
  • Added usage example for federation version override
  • Included warning about version compatibility
  • Added explanation of potential runtime issues
docs/guides/schema-export.md
RELEASE.md

Possibly linked issues

  • #3503: The PR implements the feature requested in the issue by allowing federation version override in export.

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

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Nov 14 '24 19:11 sourcery-ai[bot]

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Added option for the export_schema command to override the output federation version. usage example: strawberry export-schema --federation-version=2.5

This change ONLY affects "strawberry export-schema" command and is fully backward-compatible without any logic change.

Warning: Please use with caution!!

If the schema define directives that are not supported by the specified version (in the override parameter) the schema will still generate the output using the value from the override, and may break at runtime.

Here's the tweet text:

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

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

botberry avatar Nov 14 '24 19:11 botberry

@iotflowadmin thanks for the PR, I was wondering if we could specify the federation version when creating the schema instead, that way we could also disable some newer directives, what do you think?

patrick91 avatar Nov 15 '24 13:11 patrick91

@iotflowadmin thanks for the PR, I was wondering if we could specify the federation version when creating the schema instead, that way we could also disable some newer directives, what do you think?

@patrick91 - I think you are right, that would be a better approach. (it will enable to add some sort of IDE plugin at least for the common once, to validate on the fly that the select version actually support all the directives - should not be too hard with static code inspection).

but after digging a bit deeper in the code, I sow that it will include more effort (addressing it in more components that take place in runtime, and not only in generation.) and I just needed a quick fix cause I was testing migration from the guild which support up to 2.7 to wundergraph which currently support up to 2.5 (and found when looking around several people with same issue most of them just eventually changed it manually).

I think its still worth while adding it to the schema creation and may be I will send another PR when I find a bit more time to fiddle with it, but this tow approaches do not necessarily cancel each other and can serve for different purposes for example: I want to deploy the schema to tow environments with different max version support and I want to be on latest available on both... so I would do it with the schema generation as part of my CI/CD process, rather then managing separate code version for each environment.

iotflowadmin avatar Nov 22 '24 17:11 iotflowadmin

we are stuck in the strawberry 0.221.1 version in the company that I work because we need this feature, if I can contribute with something, please contact me

gustavosett avatar Nov 04 '25 15:11 gustavosett

I might work on this soon, I had some ideas on improving how we handle federation but didn't start just yet

@gustavosett is your company interested in sponsoring btw? :D

patrick91 avatar Nov 04 '25 21:11 patrick91

I might work on this soon, I had some ideas on improving how we handle federation but didn't start just yet

@gustavosett is your company interested in sponsoring btw? :D

I will forward the request to the responsible department

gustavosett avatar Nov 04 '25 22:11 gustavosett

@gustavosett thanks, do you want to try this prerelease (see the PR for docs)?

https://github.com/strawberry-graphql/strawberry/pull/4045#issuecomment-3499706703

patrick91 avatar Nov 06 '25 22:11 patrick91