我遇到了这个错误:
AssertionError:CreateContact字段必须是一个以字段名作为键的映射(dict / OrderedDict),或者是一个返回此类映射的函数。
当我尝试编译代码时。
我将代码包装为烧瓶蓝图,并且使用了flask-sqlalchemy,graphene和graphene_sqlalchemy。
我的突变类别如下:
from .models import User as UserModel
from .graph.models import Contact as ContactModel
from .database import db_session
from graphene_sqlalchemy import SQLAlchemyConnectionField, SQLAlchemyObjectType
import graphene
from graphene import relay
class Contact(SQLAlchemyObjectType):
class Meta:
model = ContactModel
interfaces = (relay.Node, )
class User(SQLAlchemyObjectType):
class Meta:
model = UserModel
interfaces = (relay.Node, )
class CreateContact(graphene.Mutation):
class Arguments:
name = graphene.String()
phone = graphene.String()
address = graphene.String()
zip_code = graphene.String()
url = graphene.String()
email = graphene.String()
@classmethod
def mutate(cls, _, args, context, info):
contact = ContactModel(
name=args.get('name'),
phone=args.get('phone'),
address=args.get('address'),
zip_code=args.get('zip_code'),
url=args.get('url'),
email=args.get('email'),
)
db_session.add(contact)
db_session.commit()
return CreateContact(contact=contact)
我的查询和变异类是:
class Query(graphene.ObjectType):
node = relay.Node.Field()
contacts = SQLAlchemyConnectionField(Contact.connection)
class Mutation(graphene.ObjectType):
create_contacs = CreateContact.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
我的代码的结构如下:
API应用程序:
-Dashboard (folder):
--errors (folder)
--graph (folder)
----__init__.py
----controller.py
----database.py
----models.py
----schema.py
--main (folder)
--static (folder)
--templates (folder)
--users (folder)
__init__.py
config.py
models.py
'''