gpt4 book ai didi

python - 如何使用过滤器搜索特定数据集

转载 作者:行者123 更新时间:2023-11-28 18:56:58 25 4
gpt4 key购买 nike

我有一个标签模型,我想搜索具有特定名称的特定标签。这是我目前所拥有的。

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
}
}

但是我收到了这个错误

image

你能告诉我我做错了什么吗?谢谢

最佳答案

您的查询tagToFind fileld(应该是蛇形)但是您解析了一个find_tag 所以 Graphite 烯找不到它。

tagToFind 更改为 find_tag 以修复它。

关于python - 如何使用过滤器搜索特定数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57213967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com