Skip to content

Commit

Permalink
refact: FederationDirective -> ComposableDirective
Browse files Browse the repository at this point in the history
  • Loading branch information
mak626 committed Jan 18, 2024
1 parent 7eb319b commit 436eb88
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ You can define custom directives as follows
from graphene import Field, ObjectType, String
from graphql import GraphQLArgument, GraphQLInt, GraphQLNonNull

from graphene_federation import DirectiveLocation, FederationDirective
from graphene_federation import DirectiveLocation, ComposableDirective
from graphene_federation import build_schema

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

from graphene_federation import DirectiveLocation, FederationDirective, build_schema, compose_directive, link_directive
from graphene_federation import DirectiveLocation, ComposableDirective, build_schema, compose_directive, link_directive

CacheDirective = FederationDirective(
CacheDirective = ComposableDirective(
name="cache",
locations=[DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.OBJECT],
args={
Expand Down
6 changes: 3 additions & 3 deletions graphene_federation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from graphene_directives import DirectiveLocation

from .apollo_versions import FederationVersion, LATEST_VERSION
from .composable_directive import ComposableDirective
from .directives import (
authenticated,
extends,
Expand All @@ -16,16 +17,15 @@
shareable,
tag,
)
from .federation_directive import FederationDirective
from .main import build_schema
from .schema import build_schema
from .schema_directives import compose_directive, link_directive
from .service import get_sdl

__all__ = [
"FederationVersion",
"LATEST_VERSION",
"build_schema",
"FederationDirective",
"ComposableDirective",
"DirectiveLocation",
"authenticated",
"extends",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)


class FederationDirective(GraphQLDirective):
class ComposableDirective(GraphQLDirective):
def __init__(
self,
name: str,
Expand All @@ -35,7 +35,7 @@ def __init__(
:param add_to_schema_directives: Adds schema_directives @composeDirective and @link to schema automatically
"""
if add_to_schema_directives:
assert spec_url is not None, "FederationDirective requires spec_url"
assert spec_url is not None, "ComposableDirective requires spec_url"

self.spec_url = spec_url
self.add_to_schema_directives = add_to_schema_directives
Expand Down
8 changes: 4 additions & 4 deletions graphene_federation/main.py → graphene_federation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
)
from graphene_directives.schema import Schema

from . import FederationDirective
from .apollo_versions import (
FederationVersion,
LATEST_VERSION,
get_directive_from_name,
get_directives_based_on_version,
)
from .apollo_versions.v2_1 import compose_directive as ComposeDirective
from .composable_directive import ComposableDirective
from .entity import get_entity_query
from .schema_directives import compose_directive, link_directive
from .service import get_service_query
Expand Down Expand Up @@ -65,7 +65,7 @@ def build_schema(
mutation: Union[ObjectType, Type[ObjectType]] = None,
subscription: Union[ObjectType, Type[ObjectType]] = None,
types: Collection[Union[ObjectType, Type[ObjectType]]] = None,
directives: Union[Collection[FederationDirective], None] = None,
directives: Union[Collection[ComposableDirective], None] = None,
include_graphql_spec_directives: bool = True,
schema_directives: Collection[SchemaDirective] = None,
auto_camelcase: bool = True,
Expand Down Expand Up @@ -169,8 +169,8 @@ def build_schema(
url__imports: dict[str, list[str]] = {}
for directive in directives:
assert isinstance(
directive, FederationDirective
), "directives must be of instance FederationDirective"
directive, ComposableDirective
), "directives must be of instance ComposableDirective"

if not directive.add_to_schema_directives:
continue
Expand Down
2 changes: 1 addition & 1 deletion graphene_federation/schema_directives/compose_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def compose_directive(
Use this in the `schema_directives` argument of `build_schema`
It is not recommended to use this directive directly, instead use the FederationDirective class to build
It is not recommended to use this directive directly, instead use the ComposableDirective class to build
a custom directive. It will automatically add the compose and link directive to schema
Reference: https://www.apollographql.com/docs/federation/federated-types/federated-directives/#composedirective
Expand Down
2 changes: 1 addition & 1 deletion graphene_federation/schema_directives/link_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def link_directive(
Use this in the `schema_directives` argument of `build_schema`
It is not recommended to use this directive directly, instead use the FederationDirective class to build
It is not recommended to use this directive directly, instead use the ComposableDirective class to build
a custom directive. It will automatically add the compose and link directive to schema
Also, the apollo directives such as @key, @external, ... are automatically added to the schema via the link directive
Expand Down

0 comments on commit 436eb88

Please sign in to comment.