mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
create nodes throw terminal
This commit is contained in:
parent
45104749a0
commit
f44babe153
|
@ -12,15 +12,14 @@ INSTALLED_APPS = [app for app in settings.INSTALLED_APPS if 'django' not in app]
|
||||||
|
|
||||||
PY_FILES = ['node.py', 'edge.py', '__init__.py', 'lib.py', 'resolvers.py']
|
PY_FILES = ['node.py', 'edge.py', '__init__.py', 'lib.py', 'resolvers.py']
|
||||||
|
|
||||||
pythonic_init = """
|
pythonic_init = """from .node import {model_name}Node
|
||||||
from .node import {model_name}Node
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pythonic_node = """
|
pythonic_node = """#encoding=utf-8
|
||||||
#encoding=utf-8
|
|
||||||
|
|
||||||
from lazy_import import lazy_module, lazy_callable
|
from lazy_import import lazy_module, lazy_callable
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
|
from graphene_django.relationship import EdgeNode # edge initialization
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
|
|
||||||
# lazy_modules imports
|
# lazy_modules imports
|
||||||
|
@ -35,9 +34,9 @@ class {model_name}Node(DjangoObjectType):
|
||||||
)
|
)
|
||||||
model = {model_name}
|
model = {model_name}
|
||||||
|
|
||||||
neomodel_filter_fields = {
|
neomodel_filter_fields = {{
|
||||||
# announce here dynamic filtering
|
# announce here dynamic filtering
|
||||||
}
|
}}
|
||||||
only_fields = ()
|
only_fields = ()
|
||||||
exclude_fields = ()
|
exclude_fields = ()
|
||||||
|
|
||||||
|
@ -78,6 +77,7 @@ class CommandArguments(BaseCommand):
|
||||||
"--app-module-models",
|
"--app-module-models",
|
||||||
type=str,
|
type=str,
|
||||||
dest="app_module_models",
|
dest="app_module_models",
|
||||||
|
default="models",
|
||||||
help="Choose the module of models",
|
help="Choose the module of models",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -93,7 +93,7 @@ class Command(CommandArguments):
|
||||||
help = "Django-GraphQL management module"
|
help = "Django-GraphQL management module"
|
||||||
can_import_settings = True
|
can_import_settings = True
|
||||||
|
|
||||||
def interpretate_model_to_graphqQL(self,
|
def interpretate_model_to_graphQL(self,
|
||||||
model,
|
model,
|
||||||
out_application,
|
out_application,
|
||||||
application,
|
application,
|
||||||
|
@ -112,16 +112,21 @@ class Command(CommandArguments):
|
||||||
package_path = os.path.join(output_path, package_dir)
|
package_path = os.path.join(output_path, package_dir)
|
||||||
if os.path.exists(package_dir):
|
if os.path.exists(package_dir):
|
||||||
raise CommandError('Files for %s model already exists' % package_dir.capitalize())
|
raise CommandError('Files for %s model already exists' % package_dir.capitalize())
|
||||||
print("Create path environment %s" % package_dir)
|
try:
|
||||||
os.mkdir(package_path)
|
print("Create path environment %s" % package_dir)
|
||||||
for file_name in PY_FILES:
|
os.mkdir(package_path)
|
||||||
with open(os.path.join(package_path, file_name), 'w') as file:
|
for file_name in PY_FILES:
|
||||||
if file_name == "node.py":
|
with open(os.path.join(package_path, file_name), 'w') as file:
|
||||||
file.write(pythonic_node.format(application=application,
|
if file_name == "node.py":
|
||||||
model_module=app_module_models,
|
file.write(pythonic_node.format(application=application,
|
||||||
model_name=model.__name__))
|
model_module=app_module_models,
|
||||||
elif file_name == '__init__.py':
|
model_name=model.__name__))
|
||||||
file.write(pythonic_init.format(model.__name__))
|
elif file_name == '__init__.py':
|
||||||
|
file.write(pythonic_init.format(model_name=model.__name__))
|
||||||
|
else:
|
||||||
|
file.write("")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,40 +147,8 @@ class Command(CommandArguments):
|
||||||
if out_application not in INSTALLED_APPS:
|
if out_application not in INSTALLED_APPS:
|
||||||
raise CommandError('Application %s does\'nt exists' % out_application)
|
raise CommandError('Application %s does\'nt exists' % out_application)
|
||||||
for model in models:
|
for model in models:
|
||||||
self.intepretate_model_to_graphQL(model,
|
self.interpretate_model_to_graphQL(model,
|
||||||
out_application,
|
out_application,
|
||||||
application,
|
application,
|
||||||
app_module_models)
|
app_module_models)
|
||||||
|
|
||||||
|
|
||||||
# options_schema = options.get("schema")
|
|
||||||
|
|
||||||
# if options_schema and type(options_schema) is str:
|
|
||||||
# module_str, schema_name = options_schema.rsplit(".", 1)
|
|
||||||
# mod = importlib.import_module(module_str)
|
|
||||||
# schema = getattr(mod, schema_name)
|
|
||||||
|
|
||||||
# elif options_schema:
|
|
||||||
# schema = options_schema
|
|
||||||
|
|
||||||
# else:
|
|
||||||
# schema = graphene_settings.SCHEMA
|
|
||||||
|
|
||||||
# out = options.get("out") or graphene_settings.SCHEMA_OUTPUT
|
|
||||||
|
|
||||||
# if not schema:
|
|
||||||
# raise CommandError(
|
|
||||||
# "Specify schema on GRAPHENE.SCHEMA setting or by using --schema"
|
|
||||||
# )
|
|
||||||
|
|
||||||
# indent = options.get("indent")
|
|
||||||
# schema_dict = {"data": schema.introspect()}
|
|
||||||
# if out == '-':
|
|
||||||
# self.stdout.write(json.dumps(schema_dict, indent=indent))
|
|
||||||
# else:
|
|
||||||
# self.save_file(out, schema_dict, indent)
|
|
||||||
|
|
||||||
# style = getattr(self, "style", None)
|
|
||||||
# success = getattr(style, "SUCCESS", lambda x: x)
|
|
||||||
|
|
||||||
# self.stdout.write(success("Successfully dumped GraphQL schema to %s" % out))
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user