diff --git a/graphene_django/management/commands/graphql.py b/graphene_django/management/commands/graphql.py index 69a7e80..8f3e9de 100644 --- a/graphene_django/management/commands/graphql.py +++ b/graphene_django/management/commands/graphql.py @@ -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'] -pythonic_init = """ -from .node import {model_name}Node +pythonic_init = """from .node import {model_name}Node """ -pythonic_node = """ -#encoding=utf-8 +pythonic_node = """#encoding=utf-8 from lazy_import import lazy_module, lazy_callable from graphene_django import DjangoObjectType +from graphene_django.relationship import EdgeNode # edge initialization from graphene.relay import Node # lazy_modules imports @@ -35,9 +34,9 @@ class {model_name}Node(DjangoObjectType): ) model = {model_name} - neomodel_filter_fields = { + neomodel_filter_fields = {{ # announce here dynamic filtering - } + }} only_fields = () exclude_fields = () @@ -78,6 +77,7 @@ class CommandArguments(BaseCommand): "--app-module-models", type=str, dest="app_module_models", + default="models", help="Choose the module of models", ) parser.add_argument( @@ -93,7 +93,7 @@ class Command(CommandArguments): help = "Django-GraphQL management module" can_import_settings = True - def interpretate_model_to_graphqQL(self, + def interpretate_model_to_graphQL(self, model, out_application, application, @@ -112,16 +112,21 @@ class Command(CommandArguments): package_path = os.path.join(output_path, package_dir) if os.path.exists(package_dir): raise CommandError('Files for %s model already exists' % package_dir.capitalize()) - print("Create path environment %s" % package_dir) - os.mkdir(package_path) - for file_name in PY_FILES: - with open(os.path.join(package_path, file_name), 'w') as file: - if file_name == "node.py": - file.write(pythonic_node.format(application=application, - model_module=app_module_models, - model_name=model.__name__)) - elif file_name == '__init__.py': - file.write(pythonic_init.format(model.__name__)) + try: + print("Create path environment %s" % package_dir) + os.mkdir(package_path) + for file_name in PY_FILES: + with open(os.path.join(package_path, file_name), 'w') as file: + if file_name == "node.py": + file.write(pythonic_node.format(application=application, + model_module=app_module_models, + model_name=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: raise CommandError('Application %s does\'nt exists' % out_application) for model in models: - self.intepretate_model_to_graphQL(model, + self.interpretate_model_to_graphQL(model, out_application, application, 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))