将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”?