graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

graphql_schema --out=-.graphql raises error

Open andrei-datcu opened this issue 3 years ago • 1 comments

  • What is the current behavior? Executing python manage.py graphql_schema --schema theapp.schema --out=-.graphql results in
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))

  • Please tell us about your environment:

    • Version: 3.0.0.b7
    • Platform: python 3.9
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

andrei-datcu avatar Jan 06 '21 21:01 andrei-datcu

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)

devkral avatar Dec 15 '21 21:12 devkral