mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
Allow graphql schema export to use a canonical representation
This commit is contained in:
parent
ea2cd9894f
commit
1ca44b55cb
|
@ -11,7 +11,7 @@ data to ``schema.json`` that is compatible with babel-relay-plugin.
|
|||
Usage
|
||||
-----
|
||||
|
||||
Include ``graphene_django`` to ``INSTALLED_APPS`` in you project
|
||||
Include ``graphene_django`` to ``INSTALLED_APPS`` in your project
|
||||
settings:
|
||||
|
||||
.. code:: python
|
||||
|
@ -29,6 +29,8 @@ It dumps your full introspection schema to ``schema.json`` inside your
|
|||
project root directory. Point ``babel-relay-plugin`` to this file and
|
||||
you're ready to use Relay with Graphene GraphQL implementation.
|
||||
|
||||
The schema file is sorted to create a reproducible canonical representation.
|
||||
|
||||
Advanced Usage
|
||||
--------------
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class Command(CommandArguments):
|
|||
|
||||
def save_file(self, out, schema_dict, indent):
|
||||
with open(out, "w") as outfile:
|
||||
json.dump(schema_dict, outfile, indent=indent)
|
||||
json.dump(schema_dict, outfile, indent=indent, sort_keys=True)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
options_schema = options.get("schema")
|
||||
|
@ -65,7 +65,7 @@ class Command(CommandArguments):
|
|||
indent = options.get("indent")
|
||||
schema_dict = {"data": schema.introspect()}
|
||||
if out == '-':
|
||||
self.stdout.write(json.dumps(schema_dict, indent=indent))
|
||||
self.stdout.write(json.dumps(schema_dict, indent=indent, sort_keys=True))
|
||||
else:
|
||||
self.save_file(out, schema_dict, indent)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.core import management
|
||||
from mock import patch
|
||||
from mock import patch, mock_open
|
||||
from six import StringIO
|
||||
|
||||
|
||||
|
@ -8,3 +8,15 @@ def test_generate_file_on_call_graphql_schema(savefile_mock, settings):
|
|||
out = StringIO()
|
||||
management.call_command("graphql_schema", schema="", stdout=out)
|
||||
assert "Successfully dumped GraphQL schema to schema.json" in out.getvalue()
|
||||
|
||||
|
||||
@patch('json.dump')
|
||||
def test_files_are_sorted(dump_mock):
|
||||
open_mock = mock_open()
|
||||
with patch('graphene_django.management.commands.graphql_schema.open', open_mock):
|
||||
management.call_command('graphql_schema', schema='')
|
||||
|
||||
open_mock.assert_called_once()
|
||||
|
||||
dump_mock.assert_called_once()
|
||||
assert dump_mock.call_args[1]["sort_keys"], "json.mock() should be used to sort the output"
|
||||
|
|
Loading…
Reference in New Issue
Block a user