3

現在、グラフェンのチュートリアルで GraphQL を学習していますが、実行しようとすると次のエラー メッセージが表示されました。

python3 manage.py graphql_schema

エラー:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 382, in run_from_argv
parser = self.create_parser(argv[0], argv[1])
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 355, in create_parser
self.add_arguments(parser)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/graphene_django/management/commands/graphql_schema.py", line 39, in add_arguments
default=graphene_settings.SCHEMA,
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/graphene_django/settings.py", line 110, in __getattr__
    val = perform_import(val, attr)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/graphene_django/settings.py", line 54, in perform_import
    return import_from_string(val, setting_name)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/graphene_django/settings.py", line 68, in import_from_string
    module = importlib.import_module(module_path)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/lebeier/Documents/cookbook/schema.py", line 3, in <module>
import ingredients.schema
  File "/Users/lebeier/Documents/cookbook/ingredients/schema.py", line 33, in <module>
class Query(AbstractType):
  File "/Users/lebeier/Documents/cookbook/ingredients/schema.py", line 38, in Query
all_ingredients = DjangoFilterConnectionField(IngredientNode)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/graphene_django/filter/fields.py", line 20, in __init__
self.filterset_class = get_filterset_class(filterset_class, **meta)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/graphene_django/filter/utils.py", line 32, in get_filterset_class
return custom_filterset_factory(**meta)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/graphene_django/filter/filterset.py", line 127, in custom_filterset_factory
    'Meta': meta_class
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/graphene_django/filter/filterset.py", line 55, in __new__
    new_class = super(GrapheneFilterSetMetaclass, cls).__new__(cls, name, bases, attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django_filters/filterset.py", line 224, in __new__
    filters[order_by_field] = new_class.get_ordering_filter(opts, filters)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django_filters/filterset.py", line 375, in get_ordering_filter
    "'order_by' is not compatible with the 'fields' dict syntax. Use OrderingFilter instead."
AssertionError: 'order_by' is not compatible with the 'fields' dict syntax. Use OrderingFilter instead.

私の成分/schema.pyで:

# cookbook/ingredients/schema.py
from graphene import relay, ObjectType, AbstractType
from graphene_django import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField

from .models import Category, Ingredient

# Graphene will automatically map the Category model's fields onto the CategoryNode.
# This is configured in the CategoryNode's Meta class (as you can see below)
class CategoryNode(DjangoObjectType):
    class Meta:
        model = Category
        filter_fields = ['name', 'ingredients']
        filter_order_by_field = ['name']
        interfaces = (relay.Node, )


class IngredientNode(DjangoObjectType):
    class Meta:
        model = Ingredient
        # Allow for some more advanced filtering here
        filter_fields = {
            'name': ['exact', 'icontains', 'istartswith'],
            'notes': ['exact', 'icontains'],
            'category': ['exact'],
            'category__name': ['exact'],
        }
        order_by_field = ['name', 'category__name']
        interfaces = (relay.Node, )


class Query(AbstractType):
    category = relay.Node.Field(CategoryNode)
    all_categories = DjangoFilterConnectionField(CategoryNode)

    ingredient = relay.Node.Field(IngredientNode)
    all_ingredients = DjangoFilterConnectionField(IngredientNode)

django-filter バージョン 0.15.3

公式のグラフェン リポジトリから例を複製しようとしましたが、python2.7 で問題なく動作しました。ただし、python3.5 では、同じコードが機能しませんでした。django-filter で何かが変更され、互換性がなくなったのではないかと疑っています。python2.7 では、django-filter のバージョンは 0.11.0 です。0.15.3 で動作させる方法を知っている人はいますか?

4

2 に答える 2

2

これは github の問題として報告され、現在は修正されています: https://github.com/graphql-python/graphene-django/issues/8

グラフェン 1.1 にアップグレードすれば、準備完了です。

于 2016-11-15T22:46:34.557 に答える