-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinaccessible.py
81 lines (59 loc) · 1.89 KB
/
inaccessible.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import graphene
from graphene_federation import (
LATEST_VERSION,
inaccessible,
external,
provides,
key,
override,
)
from graphene_federation import build_schema
@key(fields="x")
class Position(graphene.ObjectType):
x = graphene.Int(required=True)
y = external(graphene.Int(required=True))
z = inaccessible(graphene.Int(required=True))
a = provides(graphene.Int(), fields="x")
b = override(graphene.Int(required=True), from_="h")
@inaccessible
class ReviewInterface(graphene.Interface):
interfaced_body = graphene.String(required=True)
@inaccessible
class Review(graphene.ObjectType):
class Meta:
interfaces = (ReviewInterface,)
id = graphene.Int(required=True)
body = graphene.String(required=True)
@inaccessible
class Human(graphene.ObjectType):
name = graphene.String()
born_in = graphene.String()
@inaccessible
class Droid(graphene.ObjectType):
name = graphene.String()
primary_function = graphene.String()
@inaccessible
class Starship(graphene.ObjectType):
name = graphene.String()
length = graphene.Int()
@inaccessible
class SearchResult(graphene.Union):
class Meta:
types = (Human, Droid, Starship)
class Query(graphene.ObjectType):
position = graphene.Field(Position)
schema = build_schema(
Query,
federation_version=LATEST_VERSION,
types=(ReviewInterface, SearchResult, Review),
)
query = """
query getSDL {
_service {
sdl
}
}
"""
result = schema.execute(query)
print(result.data)
# {'_service': {'sdl': 'extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@external", "@key", "@override", "@provides", "@inaccessible"])\ntype Query {\n position: Position\n}\n\ntype Position @key(fields: "x") {\n x: Int!\n y: Int! @external\n z: Int! @inaccessible\n a: Int @provides(fields: "x")\n b: Int! @override(from: "h")\n}'}}