File tree 2 files changed +54
-0
lines changed 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 3
3
import graphene
4
4
from graphene import Schema , ObjectType
5
5
from graphene .types .definitions import GrapheneObjectType
6
+ from graphene .types .enum import EnumOptions
6
7
from graphene .types .scalars import ScalarOptions
7
8
from graphene .types .union import UnionOptions
8
9
from graphene .utils .str_converters import to_camel_case
@@ -93,6 +94,7 @@ def get_attributed_fields(attribute: str, schema: Schema):
93
94
not hasattr (type_ , "graphene_type" )
94
95
or isinstance (type_ .graphene_type ._meta , UnionOptions )
95
96
or isinstance (type_ .graphene_type ._meta , ScalarOptions )
97
+ or isinstance (type_ .graphene_type ._meta , EnumOptions )
96
98
):
97
99
continue
98
100
for field in list (type_ .graphene_type ._meta .fields ):
You can’t perform that action at this time.
0 commit comments