我有一个标签模型,我想搜索具有特定名称的特定标签。这是我到目前为止所拥有的。
from datetime import datetime
from graphene_sqlalchemy import SQLAlchemyObjectType,SQLAlchemyConnectionField
from database.base import db_session
from database.models.model_post import ModelPost
from database.models.model_image import ModelImage
from database.models.model_posttag import PostsTags
from database.models.model_tag import ModelTag
from database.models.model_user import ModelUser
from database.models.model_locale import ModelLocale
import graphene
from helpers import utils
# Create a generic class to mutualize description of user attributes for both queries and mutations
class TagAttribute:
name = graphene.String(description="Tag Name")
isactive = graphene.Boolean(description="is active")
class Tag(SQLAlchemyObjectType):
"""Tag node."""
class Meta:
model = ModelTag
interfaces = (graphene.relay.Node,)
class Query(graphene.ObjectType):
tagToFind = graphene.Field(lambda: Tag, name=graphene.String())
def resolve_find_tag(self, info, **kwargs):
query = Tag.get_query(info)
name = kwargs.get("name")
return query.filter(TagModel.name == name).first()
class CreateTagInput(graphene.InputObjectType, TagAttribute):
"""Arguments to create a tag."""
pass
class CreateTag(graphene.Mutation):
"""Mutation to create a tag."""
tag = graphene.Field(lambda: Tag, description="tag created by this mutation.")
class Arguments:
input = CreateTagInput(required=True)
def mutate(self, info, input):
data = utils.input_to_dictionary(input)
data['created_at'] = datetime.utcnow()
data['updated_at'] = datetime.utcnow()
tag = ModelTag(**data)
db_session.add(tag)
db_session.commit()
return CreateTag(tag=tag)
class UpdateTagInput(graphene.InputObjectType, TagAttribute):
"""Arguments to update a tag."""
id = graphene.ID(required=True, description="Global Id of the tag.")
class UpdateTag(graphene.Mutation):
"""Update a tag."""
tag = graphene.Field(lambda: Tag, description="tag updated by this mutation.")
class Arguments:
input = UpdateTagInput(required=True)
def mutate(self, info, input):
data = utils.input_to_dictionary(input)
data['updated_at'] = datetime.utcnow()
tag = db_session.query(ModelTag).filter_by(id=data['id'])
tag.update(data)
db_session.commit()
tag = db_session.query(ModelTag).filter_by(id=data['id']).first()
return UpdateTag(tag=tag)
这是我的一个查询
query FindTagByName($name: String ="searchstring"){
findTag(name: $name) {
id
name
}
}
但我收到了这个错误
你能告诉我我在这里做错了什么吗?谢谢