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
|
from ariadne import SchemaDirectiveVisitor, ObjectType
from . mutations import *
def non(arg):
pass
class VyosDirective(SchemaDirectiveVisitor):
def visit_field_definition(self, field, object_type, make_resolver=non):
name = f'{field.type}'
# field.type contains the return value of the mutation; trim value
# to produce canonical name
name = name.replace('Result', '', 1)
func = make_resolver(name)
field.resolve = func
return field
class ConfigureDirective(VyosDirective):
"""
Class providing implementation of 'configure' directive in schema.
"""
def visit_field_definition(self, field, object_type):
super().visit_field_definition(field, object_type,
make_resolver=make_configure_resolver)
class ShowConfigDirective(VyosDirective):
"""
Class providing implementation of 'show' directive in schema.
"""
def visit_field_definition(self, field, object_type):
super().visit_field_definition(field, object_type,
make_resolver=make_show_config_resolver)
class ConfigFileDirective(VyosDirective):
"""
Class providing implementation of 'configfile' directive in schema.
"""
def visit_field_definition(self, field, object_type):
super().visit_field_definition(field, object_type,
make_resolver=make_config_file_resolver)
class ShowDirective(VyosDirective):
"""
Class providing implementation of 'show' directive in schema.
"""
def visit_field_definition(self, field, object_type):
super().visit_field_definition(field, object_type,
make_resolver=make_show_resolver)
class ImageDirective(VyosDirective):
"""
Class providing implementation of 'image' directive in schema.
"""
def visit_field_definition(self, field, object_type):
super().visit_field_definition(field, object_type,
make_resolver=make_image_resolver)
directives_dict = {"configure": ConfigureDirective,
"showconfig": ShowConfigDirective,
"configfile": ConfigFileDirective,
"show": ShowDirective,
"image": ImageDirective}
|