File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ import graphene
2+ from graphene import ObjectType
3+ from graphql import graphql_sync
4+
5+ from graphene_federation import build_schema , shareable , inaccessible
6+
7+
8+ def test_custom_enum ():
9+ class Episode (graphene .Enum ):
10+ NEWHOPE = 4
11+ EMPIRE = 5
12+ JEDI = 6
13+
14+ @shareable
15+ class TestCustomEnum (graphene .ObjectType ):
16+ test_shareable_scalar = shareable (Episode ())
17+ test_inaccessible_scalar = inaccessible (Episode ())
18+
19+ class Query (ObjectType ):
20+ test = Episode ()
21+ test2 = graphene .List (TestCustomEnum , required = True )
22+
23+ schema = build_schema (
24+ query = Query , enable_federation_2 = True , types = (TestCustomEnum ,)
25+ )
26+ query = """
27+ query {
28+ _service {
29+ sdl
30+ }
31+ }
32+ """
33+ result = graphql_sync (schema .graphql_schema , query )
34+ assert (
35+ result .data ["_service" ]["sdl" ].strip ()
36+ == """extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@inaccessible", "@shareable"])
37+ type TestCustomEnum @shareable {
38+ testShareableScalar: Episode @shareable
39+ testInaccessibleScalar: Episode @inaccessible
40+ }
41+
42+ enum Episode {
43+ NEWHOPE
44+ EMPIRE
45+ JEDI
46+ }
47+
48+ type Query {
49+ test: Episode
50+ test2: [TestCustomEnum]!
51+ }"""
52+ )
Original file line number Diff line number Diff line change 33import graphene
44from graphene import Schema , ObjectType
55from graphene .types .definitions import GrapheneObjectType
6+ from graphene .types .enum import EnumOptions
67from graphene .types .scalars import ScalarOptions
78from graphene .types .union import UnionOptions
89from graphene .utils .str_converters import to_camel_case
@@ -93,6 +94,7 @@ def get_attributed_fields(attribute: str, schema: Schema):
9394 not hasattr (type_ , "graphene_type" )
9495 or isinstance (type_ .graphene_type ._meta , UnionOptions )
9596 or isinstance (type_ .graphene_type ._meta , ScalarOptions )
97+ or isinstance (type_ .graphene_type ._meta , EnumOptions )
9698 ):
9799 continue
98100 for field in list (type_ .graphene_type ._meta .fields ):
You can’t perform that action at this time.
0 commit comments