|
| 1 | +--- |
| 2 | +title: 0.285.0 Breaking Changes |
| 3 | +slug: breaking-changes/0.285.0 |
| 4 | +--- |
| 5 | + |
| 6 | +# v0.285.0 Breaking Changes |
| 7 | + |
| 8 | +This release removes support for Apollo Federation v1 and updates the federation |
| 9 | +API to always use Federation v2. |
| 10 | + |
| 11 | +## What Changed |
| 12 | + |
| 13 | +The `enable_federation_2` parameter has been removed and replaced with |
| 14 | +`federation_version`. Federation v2 is now always enabled, with version 2.11 as |
| 15 | +the default. |
| 16 | + |
| 17 | +```python |
| 18 | +# Before (0.284.x and earlier) |
| 19 | +schema = strawberry.federation.Schema( |
| 20 | + query=Query, enable_federation_2=True # Opt-in to Federation 2 |
| 21 | +) |
| 22 | + |
| 23 | +# After (0.285.0+) |
| 24 | +schema = strawberry.federation.Schema( |
| 25 | + query=Query, federation_version="2.11" # Defaults to "2.11", always Federation 2 |
| 26 | +) |
| 27 | +``` |
| 28 | + |
| 29 | +## Impact on Your Code |
| 30 | + |
| 31 | +### Federation v2 Users |
| 32 | + |
| 33 | +If you were already using `enable_federation_2=True`, you can remove that |
| 34 | +parameter: |
| 35 | + |
| 36 | +```python |
| 37 | +# Before |
| 38 | +schema = strawberry.federation.Schema(query=Query, enable_federation_2=True) |
| 39 | + |
| 40 | +# After |
| 41 | +schema = strawberry.federation.Schema(query=Query) |
| 42 | +``` |
| 43 | + |
| 44 | +Your schemas will continue to work without changes and will now default to |
| 45 | +Federation v2.11. |
| 46 | + |
| 47 | +### Federation v1 Users |
| 48 | + |
| 49 | +If you were using Federation v1 (without `enable_federation_2`), you **must** |
| 50 | +migrate to Federation v2. Apollo Federation v1 is no longer supported by |
| 51 | +Strawberry. |
| 52 | + |
| 53 | +Federation v2 provides better schema composition and additional features. Most |
| 54 | +v1 schemas can be migrated with minimal changes: |
| 55 | + |
| 56 | +```python |
| 57 | +# Before (Federation v1) |
| 58 | +schema = strawberry.federation.Schema(query=Query) |
| 59 | + |
| 60 | +# After (Federation v2) |
| 61 | +schema = strawberry.federation.Schema(query=Query) # Now uses v2.11 |
| 62 | +``` |
| 63 | + |
| 64 | +Key differences in Federation v2: |
| 65 | + |
| 66 | +1. **No `extend` keyword needed**: Types no longer need to be marked as |
| 67 | + extensions |
| 68 | +2. **No `@external` required**: The `@key` directive alone is sufficient in most |
| 69 | + cases |
| 70 | +3. **`@shareable` directive**: Use this to indicate fields that can be resolved |
| 71 | + by multiple subgraphs |
| 72 | +4. **`@link` directive**: Automatically added to declare federation spec version |
| 73 | + |
| 74 | +See the |
| 75 | +[Apollo Federation v2 migration guide](https://www.apollographql.com/docs/federation/federation-2/moving-to-federation-2/) |
| 76 | +for more details. |
| 77 | + |
| 78 | +## Specifying Federation Version |
| 79 | + |
| 80 | +You can now specify which Federation v2 version to use: |
| 81 | + |
| 82 | +```python |
| 83 | +schema = strawberry.federation.Schema( |
| 84 | + query=Query, federation_version="2.5" # Use a specific version |
| 85 | +) |
| 86 | +``` |
| 87 | + |
| 88 | +Supported versions: 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10, 2.11 |
| 89 | + |
| 90 | +This is useful if you need to ensure compatibility with a specific Apollo Router |
| 91 | +or Gateway version, or if you want to avoid using newer directives. |
| 92 | + |
| 93 | +### Version Validation |
| 94 | + |
| 95 | +Strawberry validates that directives are compatible with your chosen federation |
| 96 | +version: |
| 97 | + |
| 98 | +```python |
| 99 | +from strawberry.federation.schema_directives import Cost |
| 100 | + |
| 101 | + |
| 102 | +@strawberry.federation.type |
| 103 | +class Product: |
| 104 | + name: str = strawberry.federation.field( |
| 105 | + directives=[Cost(weight=10)] # Requires v2.9+ |
| 106 | + ) |
| 107 | + |
| 108 | + |
| 109 | +# This will raise an error because @cost requires v2.9+ |
| 110 | +schema = strawberry.federation.Schema( |
| 111 | + query=Query, federation_version="2.5" # Too old for @cost |
| 112 | +) |
| 113 | +``` |
| 114 | + |
| 115 | +## Why This Change? |
| 116 | + |
| 117 | +1. **Apollo Federation v1 is deprecated**: Apollo has moved to Federation v2 as |
| 118 | + the standard |
| 119 | +2. **Simpler API**: Removes the boolean flag in favor of explicit version |
| 120 | + control |
| 121 | +3. **Better features**: Federation v2 provides improved schema composition and |
| 122 | + new directives |
| 123 | +4. **Version control**: Users can now specify exact federation versions for |
| 124 | + compatibility |
| 125 | + |
| 126 | +## Migration Steps |
| 127 | + |
| 128 | +### Step 1: Check Your Current Usage |
| 129 | + |
| 130 | +If you're using `enable_federation_2=False` or not setting it at all, you're |
| 131 | +using Federation v1 and need to migrate. |
| 132 | + |
| 133 | +### Step 2: Remove Federation v1 Code |
| 134 | + |
| 135 | +```python |
| 136 | +# Remove this parameter |
| 137 | +schema = strawberry.federation.Schema( |
| 138 | + query=Query, enable_federation_2=True # Remove this line |
| 139 | +) |
| 140 | +``` |
| 141 | + |
| 142 | +### Step 3: Update Federation v1 Patterns |
| 143 | + |
| 144 | +If you were using Federation v1 patterns like `extend=True` and explicit |
| 145 | +`@external` fields, you can simplify: |
| 146 | + |
| 147 | +```python |
| 148 | +# Before (Federation v1) |
| 149 | +@strawberry.federation.type(keys=["id"], extend=True) |
| 150 | +class Product: |
| 151 | + id: strawberry.ID = strawberry.federation.field(external=True) |
| 152 | + reviews: list[Review] |
| 153 | + |
| 154 | + |
| 155 | +# After (Federation v2) |
| 156 | +@strawberry.federation.type(keys=["id"]) |
| 157 | +class Product: |
| 158 | + id: strawberry.ID |
| 159 | + reviews: list[Review] |
| 160 | +``` |
| 161 | + |
| 162 | +### Step 4: Test Your Schema |
| 163 | + |
| 164 | +Run your schema composition and tests to ensure everything works correctly with |
| 165 | +Federation v2. |
| 166 | + |
| 167 | +## Need Help? |
| 168 | + |
| 169 | +- See the [Federation guide](../guides/federation.md) for comprehensive usage |
| 170 | + examples |
| 171 | +- Review the |
| 172 | + [Apollo Federation v2 documentation](https://www.apollographql.com/docs/federation/federation-2/new-in-federation-2/) |
| 173 | +- If you encounter issues, please |
| 174 | + [report them on GitHub](https://github.com/strawberry-graphql/strawberry/issues) |
0 commit comments