summaryrefslogtreecommitdiff
path: root/src/services/api
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-11-22 11:26:58 -0600
committerJohn Estabrook <jestabro@vyos.io>2021-11-24 13:33:45 -0600
commit715b3c05b6f6bed436c7651d8a7897e8c120329b (patch)
tree1482d184f860640e2ce087b0f868abf919c6f623 /src/services/api
parentecf14b0e900c7207507196f6de6ad69c80b2e09e (diff)
downloadvyos-1x-715b3c05b6f6bed436c7651d8a7897e8c120329b.tar.gz
vyos-1x-715b3c05b6f6bed436c7651d8a7897e8c120329b.zip
graphql: T3993: change name of directive
(cherry picked from commit 6de15a4162224dbf2d911bce0a9d4eaa396071a3)
Diffstat (limited to 'src/services/api')
-rw-r--r--src/services/api/graphql/README.graphql15
-rw-r--r--src/services/api/graphql/bindings.py5
-rw-r--r--src/services/api/graphql/graphql/directives.py10
-rw-r--r--src/services/api/graphql/graphql/mutations.py2
-rw-r--r--src/services/api/graphql/graphql/schema/schema.graphql6
5 files changed, 20 insertions, 18 deletions
diff --git a/src/services/api/graphql/README.graphql b/src/services/api/graphql/README.graphql
index 0ddcb578a..a387f3276 100644
--- a/src/services/api/graphql/README.graphql
+++ b/src/services/api/graphql/README.graphql
@@ -122,13 +122,14 @@ the Ur-data; the GraphQL schema is produced from those files, located in
Resolvers for the schema Mutation fields are dynamically generated using a
'directive' added to the respective schema field. The directive,
-'@generate', is handled by the class 'DataDirective' in
-'api/graphql/graphql/directives.py', which calls the 'make_resolver' function in
-'api/graphql/graphql/mutations.py'; the produced resolver calls the appropriate
-wrapper in 'api/graphql/recipes', with base class doing the (overridable)
-configuration steps of calling all defined 'set'/'delete' commands.
-
-Integrating the above with vyos-http-api-server is ~10 lines of code.
+'@configure', is handled by the class 'ConfigureDirective' in
+'api/graphql/graphql/directives.py', which calls the
+'make_configure_resolver' function in 'api/graphql/graphql/mutations.py';
+the produced resolver calls the appropriate wrapper in
+'api/graphql/recipes', with base class doing the (overridable) configuration
+steps of calling all defined 'set'/'delete' commands.
+
+Integrating the above with vyos-http-api-server is 4 lines of code.
What needs to be done:
diff --git a/src/services/api/graphql/bindings.py b/src/services/api/graphql/bindings.py
index c123f68d8..1fbe13d0c 100644
--- a/src/services/api/graphql/bindings.py
+++ b/src/services/api/graphql/bindings.py
@@ -1,7 +1,6 @@
import vyos.defaults
from . graphql.mutations import mutation
-from . graphql.directives import DataDirective, ConfigFileDirective
-
+from . graphql.directives import directives_dict
from ariadne import make_executable_schema, load_schema_from_path, snake_case_fallback_resolvers
def generate_schema():
@@ -9,6 +8,6 @@ def generate_schema():
type_defs = load_schema_from_path(api_schema_dir)
- schema = make_executable_schema(type_defs, mutation, snake_case_fallback_resolvers, directives={"generate": DataDirective, "configfile": ConfigFileDirective})
+ schema = make_executable_schema(type_defs, mutation, snake_case_fallback_resolvers, directives=directives_dict)
return schema
diff --git a/src/services/api/graphql/graphql/directives.py b/src/services/api/graphql/graphql/directives.py
index 85d514de4..a7706610c 100644
--- a/src/services/api/graphql/graphql/directives.py
+++ b/src/services/api/graphql/graphql/directives.py
@@ -1,9 +1,9 @@
from ariadne import SchemaDirectiveVisitor, ObjectType
-from . mutations import make_resolver, make_config_file_resolver
+from . mutations import make_configure_resolver, make_config_file_resolver
-class DataDirective(SchemaDirectiveVisitor):
+class ConfigureDirective(SchemaDirectiveVisitor):
"""
- Class providing implementation of 'generate' directive in schema.
+ Class providing implementation of 'configure' directive in schema.
"""
def visit_field_definition(self, field, object_type):
@@ -12,7 +12,7 @@ class DataDirective(SchemaDirectiveVisitor):
# to produce canonical name
name = name.replace('Result', '', 1)
- func = make_resolver(name)
+ func = make_configure_resolver(name)
field.resolve = func
return field
@@ -30,3 +30,5 @@ class ConfigFileDirective(SchemaDirectiveVisitor):
func = make_config_file_resolver(name)
field.resolve = func
return field
+
+directives_dict = {"configure": ConfigureDirective, "configfile": ConfigFileDirective}
diff --git a/src/services/api/graphql/graphql/mutations.py b/src/services/api/graphql/graphql/mutations.py
index 2eb0a0b4a..8c613b9ca 100644
--- a/src/services/api/graphql/graphql/mutations.py
+++ b/src/services/api/graphql/graphql/mutations.py
@@ -9,7 +9,7 @@ from .. import state
mutation = ObjectType("Mutation")
-def make_resolver(mutation_name):
+def make_configure_resolver(mutation_name):
"""Dynamically generate a resolver for the mutation named in the
schema by 'mutation_name'.
diff --git a/src/services/api/graphql/graphql/schema/schema.graphql b/src/services/api/graphql/graphql/schema/schema.graphql
index 70fe0d726..4730f24bc 100644
--- a/src/services/api/graphql/graphql/schema/schema.graphql
+++ b/src/services/api/graphql/graphql/schema/schema.graphql
@@ -7,12 +7,12 @@ type Query {
_dummy: String
}
-directive @generate on FIELD_DEFINITION
+directive @configure on FIELD_DEFINITION
directive @configfile on FIELD_DEFINITION
type Mutation {
- createDhcpServer(data: dhcpServerConfigInput) : createDhcpServerResult @generate
- createInterfaceEthernet(data: interfaceEthernetConfigInput) : createInterfaceEthernetResult @generate
+ createDhcpServer(data: dhcpServerConfigInput) : createDhcpServerResult @configure
+ createInterfaceEthernet(data: interfaceEthernetConfigInput) : createInterfaceEthernetResult @configure
saveConfigFile(data: saveConfigFileInput) : saveConfigFileResult @configfile
loadConfigFile(data: loadConfigFileInput) : loadConfigFileResult @configfile
}