mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-01 00:17:26 +03:00 
			
		
		
		
	Merge pull request #241 from jkimbo/indent-option-schema
Added --indent option for graphql_schema command
This commit is contained in:
		
						commit
						d3995ca516
					
				|  | @ -25,6 +25,13 @@ if LT_DJANGO_1_8: | ||||||
|                 default='', |                 default='', | ||||||
|                 help='Output file (default: schema.json)' |                 help='Output file (default: schema.json)' | ||||||
|             ), |             ), | ||||||
|  |             make_option( | ||||||
|  |                 '--indent', | ||||||
|  |                 type=int, | ||||||
|  |                 dest='indent', | ||||||
|  |                 default=None, | ||||||
|  |                 help='Number of indentation spaces to use in the output', | ||||||
|  |             ), | ||||||
|         ) |         ) | ||||||
| else: | else: | ||||||
|     class CommandArguments(BaseCommand): |     class CommandArguments(BaseCommand): | ||||||
|  | @ -45,26 +52,34 @@ else: | ||||||
|                 default=getattr(settings, 'GRAPHENE_SCHEMA_OUTPUT', 'schema.json'), |                 default=getattr(settings, 'GRAPHENE_SCHEMA_OUTPUT', 'schema.json'), | ||||||
|                 help='Output file (default: schema.json)') |                 help='Output file (default: schema.json)') | ||||||
| 
 | 
 | ||||||
|  |             parser.add_argument( | ||||||
|  |                 '--indent', | ||||||
|  |                 type=int, | ||||||
|  |                 dest='indent', | ||||||
|  |                 default=getattr(settings, 'GRAPHENE_SCHEMA_INDENT', None), | ||||||
|  |                 help='Number of indentation spaces to use in the output') | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class Command(CommandArguments): | class Command(CommandArguments): | ||||||
|     help = 'Dump Graphene schema JSON to file' |     help = 'Dump Graphene schema JSON to file' | ||||||
|     can_import_settings = True |     can_import_settings = True | ||||||
| 
 | 
 | ||||||
|     def save_file(self, out, schema_dict): |     def save_file(self, out, schema_dict, indent): | ||||||
|         with open(out, 'w') as outfile: |         with open(out, 'w') as outfile: | ||||||
|             json.dump(schema_dict, outfile) |             json.dump(schema_dict, outfile, indent=indent) | ||||||
| 
 | 
 | ||||||
|     def handle(self, *args, **options): |     def handle(self, *args, **options): | ||||||
|         from django.conf import settings |         from django.conf import settings | ||||||
|         schema = options.get('schema') or getattr(settings, 'GRAPHENE_SCHEMA', '') |         schema = options.get('schema') or getattr(settings, 'GRAPHENE_SCHEMA', '') | ||||||
|         out = options.get('out') or getattr(settings, 'GRAPHENE_SCHEMA_OUTPUT', 'schema.json') |         out = options.get('out') or getattr(settings, 'GRAPHENE_SCHEMA_OUTPUT', 'schema.json') | ||||||
|  |         indent = options.get('indent') or getattr(settings, 'GRAPHENE_SCHEMA_INDENT', None) | ||||||
| 
 | 
 | ||||||
|         if schema == '': |         if schema == '': | ||||||
|             raise CommandError('Specify schema on GRAPHENE_SCHEMA setting or by using --schema') |             raise CommandError('Specify schema on GRAPHENE_SCHEMA setting or by using --schema') | ||||||
|         i = importlib.import_module(schema) |         i = importlib.import_module(schema) | ||||||
| 
 | 
 | ||||||
|         schema_dict = {'data': i.schema.introspect()} |         schema_dict = {'data': i.schema.introspect()} | ||||||
|         self.save_file(out, schema_dict) |         self.save_file(out, schema_dict, indent) | ||||||
| 
 | 
 | ||||||
|         style = getattr(self, 'style', None) |         style = getattr(self, 'style', None) | ||||||
|         SUCCESS = getattr(style, 'SUCCESS', lambda x: x) |         SUCCESS = getattr(style, 'SUCCESS', lambda x: x) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user