问题描述
我想检查用户是否存在于数据库中...如果用户存在于数据库中则发送
type user{
name
email
password
username
}
或者如果用户在数据库中不存在,则发送一个字符串,告诉“用户在数据库中不存在”
喜欢....如果我在写tyepDefs
type Query{
show_data(username: String!): #if user exists then# ***user!*** or #if user doesnot exists then# ***String!***
如何制作这种类型的解析器和 typeDefs ?
解决方法
您可以创建一个新类型以在查询中使用:
type UserPayload {
state: String! # success or other value
user: User # if state was not success this must be null
}
然后直接通过您的查询使用该类型,如下所示:
type Query{
show_data(username: String!):UserPayload
}