Файл models.py не изменился. Вот код, который я написал для ответа на возникшую у меня проблему:
import graphene
from graphene.relay import Node
from flask import Flask
from flask_graphql import GraphQLView
from graphene_mongo import MongoengineObjectType
from models import User as UserModel
from mongoengine import connect
connect(db="graphene-mongo-example",host="127.0.0.1:27017",alias="default")
class User(MongoengineObjectType):
class Meta:
model = UserModel
filter_fields = ['fisrt_name']
interfaces = (Node,)
class Query(graphene.ObjectType):
user_by_name = graphene.Field(User,gName=graphene.String())
def resolve_user_by_name(parent,info,gName):
return UserModel.objects.get(first_name=gName)
schema = graphene.Schema(query=Query)
#==================================================================
app = Flask(__name__)
app.debug = True
app.add_url_rule(
"/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True)
)
if __name__ == "__main__":
app.run()
Затем я могу запросить с помощью GraphQL такой запрос:
query {
userByName(gName:"Pierre")
{lastName
firstName
}
}