Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: Custom Enum #15

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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