Skip to content

Commit 436eb88

Browse files
committed
refact: FederationDirective -> ComposableDirective
1 parent 7eb319b commit 436eb88

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ You can define custom directives as follows
273273
from graphene import Field, ObjectType, String
274274
from graphql import GraphQLArgument, GraphQLInt, GraphQLNonNull
275275

276-
from graphene_federation import DirectiveLocation, FederationDirective
276+
from graphene_federation import DirectiveLocation, ComposableDirective
277277
from graphene_federation import build_schema
278278

279-
CacheDirective = FederationDirective(
279+
CacheDirective = ComposableDirective(
280280
name="cache",
281281
locations=[DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.OBJECT],
282282
args={
@@ -339,9 +339,9 @@ You can pass the `add_to_schema_directives` as `False`
339339
from graphene import Field, ObjectType, String
340340
from graphql import GraphQLArgument, GraphQLInt, GraphQLNonNull
341341

342-
from graphene_federation import DirectiveLocation, FederationDirective, build_schema, compose_directive, link_directive
342+
from graphene_federation import DirectiveLocation, ComposableDirective, build_schema, compose_directive, link_directive
343343

344-
CacheDirective = FederationDirective(
344+
CacheDirective = ComposableDirective(
345345
name="cache",
346346
locations=[DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.OBJECT],
347347
args={

graphene_federation/__init__.py

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

33
from .apollo_versions import FederationVersion, LATEST_VERSION
4+
from .composable_directive import ComposableDirective
45
from .directives import (
56
authenticated,
67
extends,
@@ -16,16 +17,15 @@
1617
shareable,
1718
tag,
1819
)
19-
from .federation_directive import FederationDirective
20-
from .main import build_schema
20+
from .schema import build_schema
2121
from .schema_directives import compose_directive, link_directive
2222
from .service import get_sdl
2323

2424
__all__ = [
2525
"FederationVersion",
2626
"LATEST_VERSION",
2727
"build_schema",
28-
"FederationDirective",
28+
"ComposableDirective",
2929
"DirectiveLocation",
3030
"authenticated",
3131
"extends",

graphene_federation/federation_directive.py renamed to graphene_federation/composable_directive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99

1010

11-
class FederationDirective(GraphQLDirective):
11+
class ComposableDirective(GraphQLDirective):
1212
def __init__(
1313
self,
1414
name: str,
@@ -35,7 +35,7 @@ def __init__(
3535
:param add_to_schema_directives: Adds schema_directives @composeDirective and @link to schema automatically
3636
"""
3737
if add_to_schema_directives:
38-
assert spec_url is not None, "FederationDirective requires spec_url"
38+
assert spec_url is not None, "ComposableDirective requires spec_url"
3939

4040
self.spec_url = spec_url
4141
self.add_to_schema_directives = add_to_schema_directives

graphene_federation/main.py renamed to graphene_federation/schema.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
)
1010
from graphene_directives.schema import Schema
1111

12-
from . import FederationDirective
1312
from .apollo_versions import (
1413
FederationVersion,
1514
LATEST_VERSION,
1615
get_directive_from_name,
1716
get_directives_based_on_version,
1817
)
1918
from .apollo_versions.v2_1 import compose_directive as ComposeDirective
19+
from .composable_directive import ComposableDirective
2020
from .entity import get_entity_query
2121
from .schema_directives import compose_directive, link_directive
2222
from .service import get_service_query
@@ -65,7 +65,7 @@ def build_schema(
6565
mutation: Union[ObjectType, Type[ObjectType]] = None,
6666
subscription: Union[ObjectType, Type[ObjectType]] = None,
6767
types: Collection[Union[ObjectType, Type[ObjectType]]] = None,
68-
directives: Union[Collection[FederationDirective], None] = None,
68+
directives: Union[Collection[ComposableDirective], None] = None,
6969
include_graphql_spec_directives: bool = True,
7070
schema_directives: Collection[SchemaDirective] = None,
7171
auto_camelcase: bool = True,
@@ -169,8 +169,8 @@ def build_schema(
169169
url__imports: dict[str, list[str]] = {}
170170
for directive in directives:
171171
assert isinstance(
172-
directive, FederationDirective
173-
), "directives must be of instance FederationDirective"
172+
directive, ComposableDirective
173+
), "directives must be of instance ComposableDirective"
174174

175175
if not directive.add_to_schema_directives:
176176
continue

graphene_federation/schema_directives/compose_directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def compose_directive(
1919
2020
Use this in the `schema_directives` argument of `build_schema`
2121
22-
It is not recommended to use this directive directly, instead use the FederationDirective class to build
22+
It is not recommended to use this directive directly, instead use the ComposableDirective class to build
2323
a custom directive. It will automatically add the compose and link directive to schema
2424
2525
Reference: https://www.apollographql.com/docs/federation/federated-types/federated-directives/#composedirective

graphene_federation/schema_directives/link_directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def link_directive(
3939
4040
Use this in the `schema_directives` argument of `build_schema`
4141
42-
It is not recommended to use this directive directly, instead use the FederationDirective class to build
42+
It is not recommended to use this directive directly, instead use the ComposableDirective class to build
4343
a custom directive. It will automatically add the compose and link directive to schema
4444
4545
Also, the apollo directives such as @key, @external, ... are automatically added to the schema via the link directive

0 commit comments

Comments
 (0)