Skip to content

Commit e4a69ed

Browse files
committed
deprecated: enable_federation_2 in favour of federation_version
1 parent 436eb88 commit e4a69ed

26 files changed

+160
-116
lines changed

README.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ If you need to use a version compatible with `graphene` v2 I recommend using the
3737
- [x] v2.2
3838
- [x] v2.3
3939
- [x] v2.4
40-
- [x] v2.5
41-
- [x] v2.6
40+
- [x] v2.5 `STABLE_VERSION` . Rover dev supports only upto v2.5
41+
- [x] v2.6 `LATEST_VERSION`
4242

4343
All directives could be easily integrated with the help of [graphene-directives](https://github.com/strollby/graphene-directives).
4444
Now every directive's values are validated at run time itself by [graphene-directives](https://github.com/strollby/graphene-directives).
@@ -128,7 +128,7 @@ First add an account service that expose a `User` type that can then be referenc
128128
```python
129129
from graphene import Field, Int, ObjectType, String
130130

131-
from graphene_federation import build_schema, key
131+
from graphene_federation import LATEST_VERSION, build_schema, key
132132

133133

134134
@key("id")
@@ -147,7 +147,7 @@ class Query(ObjectType):
147147
me = Field(User)
148148

149149

150-
schema = build_schema(query=Query, enable_federation_2=True)
150+
schema = build_schema(query=Query, federation_version=LATEST_VERSION)
151151
```
152152

153153
### Product
@@ -156,7 +156,7 @@ The product service exposes a `Product` type that can be used by other services
156156
```python
157157
from graphene import Argument, Int, List, ObjectType, String
158158

159-
from graphene_federation import build_schema, key
159+
from graphene_federation import LATEST_VERSION, build_schema, key
160160

161161

162162
@key("upc")
@@ -176,7 +176,7 @@ class Query(ObjectType):
176176
topProducts = List(Product, first=Argument(Int, default_value=5))
177177

178178

179-
schema = build_schema(query=Query, enable_federation_2=True)
179+
schema = build_schema(query=Query, federation_version=LATEST_VERSION)
180180
```
181181

182182
### Reviews
@@ -187,7 +187,7 @@ On top of that it adds to the `User`/`Product` types (that are both defined in o
187187
```python
188188
from graphene import Field, Int, List, ObjectType, String
189189

190-
from graphene_federation import build_schema, external, key, provides
190+
from graphene_federation import LATEST_VERSION, build_schema, external, key, provides
191191

192192

193193
@key("id")
@@ -218,7 +218,7 @@ class Query(ObjectType):
218218
review = Field(Review)
219219

220220

221-
schema = build_schema(query=Query, enable_federation_2=True)
221+
schema = build_schema(query=Query, federation_version=LATEST_VERSION)
222222
```
223223

224224
### Federation
@@ -254,10 +254,7 @@ There is also a cool [example](https://github.com/preply/graphene-federation/iss
254254

255255
- `schema_directives` (`Collection[SchemaDirective]`): Directives that can be defined at `DIRECTIVE_LOCATION.SCHEMA` with their argument values.
256256
- `include_graphql_spec_directives` (`bool`): Includes directives defined by GraphQL spec (`@include`, `@skip`, `@deprecated`, `@specifiedBy`)
257-
- `enable_federation_2` (`bool`): Whether to enable federation 2 directives (default False)
258-
- `federation_version` (`FederationVersion`): Specify the version explicit (default LATEST_VERSION)
259-
260-
In case both enable_federation_2 and federation_version are specified, federation_version is given higher priority
257+
- `federation_version` (`FederationVersion`): Specify the version explicit (default STABLE_VERSION)
261258

262259
### Directives Additional arguments
263260

@@ -273,7 +270,7 @@ You can define custom directives as follows
273270
from graphene import Field, ObjectType, String
274271
from graphql import GraphQLArgument, GraphQLInt, GraphQLNonNull
275272

276-
from graphene_federation import DirectiveLocation, ComposableDirective
273+
from graphene_federation import ComposableDirective, DirectiveLocation, LATEST_VERSION
277274
from graphene_federation import build_schema
278275

279276
CacheDirective = ComposableDirective(
@@ -293,7 +290,7 @@ cache = CacheDirective.decorator()
293290

294291
@cache(max_age=20)
295292
class Review(ObjectType):
296-
body = cache(field=String(),max_age=100)
293+
body = cache(field=String(), max_age=100)
297294

298295

299296
class Query(ObjectType):
@@ -303,7 +300,7 @@ class Query(ObjectType):
303300
schema = build_schema(
304301
query=Query,
305302
directives=(CacheDirective,),
306-
enable_federation_2=True,
303+
federation_version=LATEST_VERSION ,
307304
)
308305
```
309306

@@ -339,7 +336,8 @@ You can pass the `add_to_schema_directives` as `False`
339336
from graphene import Field, ObjectType, String
340337
from graphql import GraphQLArgument, GraphQLInt, GraphQLNonNull
341338

342-
from graphene_federation import DirectiveLocation, ComposableDirective, build_schema, compose_directive, link_directive
339+
from graphene_federation import (ComposableDirective, DirectiveLocation, LATEST_VERSION, build_schema,
340+
compose_directive, link_directive)
343341

344342
CacheDirective = ComposableDirective(
345343
name="cache",
@@ -372,7 +370,7 @@ schema = build_schema(
372370
link_directive(url="https://specs.example.dev/directives/v1.0", import_=['@cache']),
373371
compose_directive(name='@cache'),
374372
),
375-
enable_federation_2=True,
373+
federation_version=LATEST_VERSION,
376374
)
377375
```
378376

@@ -392,7 +390,7 @@ class User(ObjectType):
392390
class Query(ObjectType):
393391
user = Field(User)
394392

395-
schema = build_schema(query=Query, enable_federation_2=True, auto_camelcase=False) # Disable auto_camelcase
393+
schema = build_schema(query=Query, federation_version=LATEST_VERSION, auto_camelcase=False) # Disable auto_camelcase
396394
```
397395

398396
This works correctly.
@@ -409,7 +407,7 @@ class User(ObjectType):
409407
class Query(ObjectType):
410408
user = Field(User)
411409

412-
schema = build_schema(query=Query, enable_federation_2=True) # auto_camelcase Enabled
410+
schema = build_schema(query=Query, federation_version=LATEST_VERSION) # auto_camelcase Enabled
413411
```
414412

415413
This will raise an error `@key, field "validEmail" does not exist on type "User"`.
@@ -427,7 +425,7 @@ class User(ObjectType):
427425
class Query(ObjectType):
428426
user = Field(User)
429427

430-
schema = build_schema(query=Query, enable_federation_2=True) # auto_camelcase=True
428+
schema = build_schema(query=Query, federation_version=LATEST_VERSION) # auto_camelcase=True
431429
```
432430

433431
------------------------

examples/inaccessible.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import graphene
22

33
from graphene_federation import (
4-
inaccessible,
4+
LATEST_VERSION, inaccessible,
55
external,
66
provides,
77
key,
@@ -64,7 +64,7 @@ class Query(graphene.ObjectType):
6464

6565

6666
schema = build_schema(
67-
Query, enable_federation_2=True, types=(ReviewInterface, SearchResult, Review)
67+
Query, federation_version=LATEST_VERSION, types=(ReviewInterface, SearchResult, Review)
6868
)
6969

7070
query = """

examples/override.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import graphene
22

33
from graphene_federation import (
4-
build_schema,
4+
LATEST_VERSION, build_schema,
55
shareable,
66
external,
77
key,
@@ -21,7 +21,7 @@ class Query(graphene.ObjectType):
2121
position = graphene.Field(Product)
2222

2323

24-
schema = build_schema(Query, enable_federation_2=True)
24+
schema = build_schema(Query, federation_version=LATEST_VERSION)
2525

2626
query = """
2727
query getSDL {

examples/shareable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from graphene_federation.shareable import shareable
55

6-
from graphene_federation import build_schema
6+
from graphene_federation import LATEST_VERSION, build_schema
77

88

99
@shareable
@@ -40,7 +40,7 @@ class Query(graphene.ObjectType):
4040
position = graphene.Field(Position)
4141

4242

43-
schema = build_schema(Query, enable_federation_2=True, types=(SearchResult,))
43+
schema = build_schema(Query, federation_version=LATEST_VERSION, types=(SearchResult,))
4444

4545
query = """
4646
query getSDL {

examples/tag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import graphene
2-
3-
from graphene_federation import build_schema, key, inaccessible, shareable
42
from graphene_federation.tag import tag
53

4+
from graphene_federation import LATEST_VERSION, build_schema, inaccessible, shareable
5+
66

77
class Product(graphene.ObjectType):
88
id = graphene.ID(required=True)
@@ -15,7 +15,7 @@ class Query(graphene.ObjectType):
1515
position = graphene.Field(Product)
1616

1717

18-
schema = build_schema(Query, enable_federation_2=True)
18+
schema = build_schema(Query, federation_version=LATEST_VERSION)
1919

2020
query = """
2121
query getSDL {

graphene_federation/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from graphene_directives import DirectiveLocation
22

3-
from .apollo_versions import FederationVersion, LATEST_VERSION
3+
from .apollo_versions import FederationVersion, LATEST_VERSION, STABLE_VERSION
44
from .composable_directive import ComposableDirective
55
from .directives import (
66
authenticated,
@@ -24,6 +24,7 @@
2424
__all__ = [
2525
"FederationVersion",
2626
"LATEST_VERSION",
27+
"STABLE_VERSION",
2728
"build_schema",
2829
"ComposableDirective",
2930
"DirectiveLocation",

graphene_federation/apollo_versions/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .version import FederationVersion
1212

1313
LATEST_VERSION = FederationVersion.VERSION_2_6
14+
STABLE_VERSION = FederationVersion.VERSION_2_5
1415

1516

1617
def get_directives_based_on_version(

graphene_federation/schema.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from .apollo_versions import (
1313
FederationVersion,
14-
LATEST_VERSION,
14+
STABLE_VERSION,
1515
get_directive_from_name,
1616
get_directives_based_on_version,
1717
)
@@ -69,7 +69,6 @@ def build_schema(
6969
include_graphql_spec_directives: bool = True,
7070
schema_directives: Collection[SchemaDirective] = None,
7171
auto_camelcase: bool = True,
72-
enable_federation_2: bool = False,
7372
federation_version: FederationVersion = None,
7473
) -> Schema:
7574
"""
@@ -92,23 +91,13 @@ def build_schema(
9291
with their argument values.
9392
include_graphql_spec_directives (bool): Includes directives defined by GraphQL spec (@include, @skip,
9493
@deprecated, @specifiedBy)
95-
enable_federation_2 (bool): Whether to enable federation 2 directives (default False)
96-
federation_version (FederationVersion): Specify the version explicit (default LATEST_VERSION)
97-
98-
In case both enable_federation_2 and federation_version are specified, federation_version is given
99-
higher priority
94+
federation_version (FederationVersion): Specify the version explicit (default STABLE_VERSION)
10095
"""
10196

102-
# In case both enable_federation_2 and federation_version are specified,
103-
# federation_version is given higher priority
104-
federation_version = (
105-
federation_version
106-
if federation_version
107-
else LATEST_VERSION
108-
if enable_federation_2
109-
else FederationVersion.VERSION_1_0
97+
federation_version = federation_version if federation_version else STABLE_VERSION
98+
federation_2_enabled = (
99+
federation_version.value > FederationVersion.VERSION_1_0.value
110100
)
111-
enable_federation_2 = federation_version.value > FederationVersion.VERSION_1_0.value
112101

113102
_types = list(types) if types is not None else []
114103

@@ -135,7 +124,7 @@ def build_schema(
135124
_schema_directives = []
136125
directives_used = schema.get_directives_used()
137126
if schema_directives or directives:
138-
if not enable_federation_2:
127+
if not federation_2_enabled:
139128
raise ValueError(
140129
f"Schema Directives & Directives are not supported on {federation_version=}. Use >=2.0 "
141130
)
@@ -150,7 +139,7 @@ def build_schema(
150139
):
151140
directives_used.append(ComposeDirective)
152141

153-
if directives_used and enable_federation_2:
142+
if directives_used and federation_2_enabled:
154143
imports = [
155144
str(directive)
156145
for directive in directives_used
@@ -197,7 +186,9 @@ def build_schema(
197186
if schema_directives:
198187
_schema_directives.extend(list(schema_directives))
199188

200-
schema_args["schema_directives"] = _schema_directives if enable_federation_2 else []
189+
schema_args["schema_directives"] = (
190+
_schema_directives if federation_2_enabled else []
191+
)
201192

202193
# Call it again to rebuild the schema using the schema directives
203194
schema = build_directive_schema(query=query, **schema_args)

integration_tests/service_a/src/schema.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from graphene import Field, Int, Interface, List, NonNull, ObjectType, String
22

3-
from graphene_federation import build_schema, extends, external, key
3+
from graphene_federation import FederationVersion, build_schema, extends, external, key
44

55

66
class DecoratedText(Interface):
@@ -79,4 +79,9 @@ def resolve_goodbye(root, info):
7979
return "See ya!"
8080

8181

82-
schema = build_schema(query=Query, types=[FunnyTextAnother], auto_camelcase=False)
82+
schema = build_schema(
83+
query=Query,
84+
types=[FunnyTextAnother],
85+
federation_version=FederationVersion.VERSION_1_0,
86+
auto_camelcase=False,
87+
)

integration_tests/service_b/src/schema.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from graphene import ObjectType, String, Int, Interface, Mutation
1+
from graphene import Int, Interface, Mutation, ObjectType, String
22

3-
from graphene_federation import build_schema, key
3+
from graphene_federation import FederationVersion, build_schema, key
44

55

66
class TextInterface(Interface):
@@ -70,4 +70,6 @@ class Mutation(ObjectType):
7070

7171
types = [FileNode, FunnyText, FileNodeAnother, User]
7272

73-
schema = build_schema(mutation=Mutation, types=types)
73+
schema = build_schema(
74+
mutation=Mutation, types=types, federation_version=FederationVersion.VERSION_1_0
75+
)

integration_tests/service_c/src/schema.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
from graphene import Field, Int, List, NonNull, ObjectType, String
22

3-
from graphene_federation import build_schema, extends, external, key, provides, requires
3+
from graphene_federation import (
4+
FederationVersion,
5+
build_schema,
6+
extends,
7+
external,
8+
key,
9+
provides,
10+
requires,
11+
)
412

513

614
@key(fields="id")
@@ -54,4 +62,4 @@ def resolve_articles_with_author_age_provide(self, info):
5462
return [ArticleThatProvideAuthorAge(id=1, text="some text", author=User(id=5))]
5563

5664

57-
schema = build_schema(Query)
65+
schema = build_schema(Query, federation_version=FederationVersion.VERSION_1_0)

integration_tests/service_d/src/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from graphene import Field, Int, ObjectType
22

3-
from graphene_federation import build_schema, extends, external, key
3+
from graphene_federation import FederationVersion, build_schema, extends, external, key
44

55
"""
66
Alphabet order - matters
@@ -28,4 +28,4 @@ class Query(ObjectType):
2828
y = Field(Y)
2929

3030

31-
schema = build_schema(query=Query)
31+
schema = build_schema(query=Query, federation_version=FederationVersion.VERSION_1_0)

0 commit comments

Comments
 (0)