将makeExecutableSchema
与以下查询定义一起使用:
# Interface for simple presence in front-end.
type AccountType {
email: Email!
firstName: String!
lastName: String!
}
# The Root Query
type Query {
# Get's the account per ID or with an authToken.
getAccount(
email: Email
) : AccountType!
}
schema {
query: Query
}
以下解析器:
export default {
Query: {
async getAccount(_, {email}, { authToken }) {
/**
* Authentication
*/
//const user = security.requireAuth(authToken)
/**
* Resolution
*/
const account = await accounts.find({email})
if (account.length !== 1) {
throw new GraphQLError('No account was found with the given email.', GraphQLError.codes.GRAPHQL_NOT_FOUND)
}
return account
}
}
}
当我查询时:
query {
getAccount(email: "test@testing.com") {
firstName
lastName
}
}
我在GraphiQL中得到以下结果:
{
"data": {
"getAccount": {
"firstName": "John",
"lastName": "Doe"
}
}
}
所以,我得到这个" getAccount"回到结果?
答案 0 :(得分:1)
由于getAccount
不是查询名称。它只是根查询类型Query
上的常规字段。
与查询的完全相同的形状的结果是GraphQL的核心设计原则之一:
的屏幕截图 GraphQL中的查询名称位于query
关键字:
query myQueryName {
getAccount(email: "test@testing.com") {
firstName
lastName
}
}