graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.31k stars 769 forks source link

graphql_schema --out=-.graphql raises error #1089

Open andrei-datcu opened 3 years ago

andrei-datcu commented 3 years ago
Traceback (most recent call last):
  File "/theapp/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/env/lib/python3.9/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/env/lib/python3.9/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/env/lib/python3.9/site-packages/graphene_django/management/commands/graphql_schema.py", line 115, in handle
    self.get_schema(schema, out, indent)
  File "/env/lib/python3.9/site-packages/graphene_django/management/commands/graphql_schema.py", line 66, in get_schema
    self.stdout.write(print_schema(schema))
  File "/env/lib/python3.9/site-packages/graphql/utilities/print_schema.py", line 39, in print_schema
    return print_filtered_schema(
  File "/env/lib/python3.9/site-packages/graphql/utilities/print_schema.py", line 57, in print_filtered_schema
    directives = filter(directive_filter, schema.directives)
  File "/env/lib/python3.9/site-packages/graphene/types/schema.py", line 552, in __getattr__
    raise AttributeError(f'Type "{type_name}" not found in the Schema')
AttributeError: Type "directives" not found in the Schema

Executing python manage.py graphql_schema --schema app.schema --out=schema.graphql

succeeds with

Successfully dumped GraphQL schema to schema.graphql

If you look in the code, the former does: self.stdout.write(print_schema(schema))

the latter does:

outfile.write(print_schema(schema.graphql_schema))

devkral commented 2 years ago

the reason is the line in (graphql_schema.py in management/commands): self.stdout.write(print_schema(schema))

it should be changed to self.stdout.write(print_schema(schema.graphql_schema))

(change in graphene)