Skip to content

Commit

Permalink
Bug Fix: Custom Enum (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsureshkumar authored Mar 28, 2023
1 parent 14881c1 commit 8985776
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions graphene_federation/tests/test_custom_enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import graphene
from graphene import ObjectType
from graphql import graphql_sync

from graphene_federation import build_schema, shareable, inaccessible


def test_custom_enum():
class Episode(graphene.Enum):
NEWHOPE = 4
EMPIRE = 5
JEDI = 6

@shareable
class TestCustomEnum(graphene.ObjectType):
test_shareable_scalar = shareable(Episode())
test_inaccessible_scalar = inaccessible(Episode())

class Query(ObjectType):
test = Episode()
test2 = graphene.List(TestCustomEnum, required=True)

schema = build_schema(
query=Query, enable_federation_2=True, types=(TestCustomEnum,)
)
query = """
query {
_service {
sdl
}
}
"""
result = graphql_sync(schema.graphql_schema, query)
assert (
result.data["_service"]["sdl"].strip()
== """extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@inaccessible", "@shareable"])
type TestCustomEnum @shareable {
testShareableScalar: Episode @shareable
testInaccessibleScalar: Episode @inaccessible
}
enum Episode {
NEWHOPE
EMPIRE
JEDI
}
type Query {
test: Episode
test2: [TestCustomEnum]!
}"""
)
2 changes: 2 additions & 0 deletions graphene_federation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import graphene
from graphene import Schema, ObjectType
from graphene.types.definitions import GrapheneObjectType
from graphene.types.enum import EnumOptions
from graphene.types.scalars import ScalarOptions
from graphene.types.union import UnionOptions
from graphene.utils.str_converters import to_camel_case
Expand Down Expand Up @@ -93,6 +94,7 @@ def get_attributed_fields(attribute: str, schema: Schema):
not hasattr(type_, "graphene_type")
or isinstance(type_.graphene_type._meta, UnionOptions)
or isinstance(type_.graphene_type._meta, ScalarOptions)
or isinstance(type_.graphene_type._meta, EnumOptions)
):
continue
for field in list(type_.graphene_type._meta.fields):
Expand Down

0 comments on commit 8985776

Please sign in to comment.