【发布时间】:2017-07-18 15:33:03
【问题描述】:
我在尝试解析 GraphQL 类型中的字段时遇到问题。
所以,在这里我试图解决patientQuery的find属性
const gqlSchema = makeExecutableSchema({
typeDefs: `
type patientQuery {
find: [String]
findOne: String
}
type Query {
patient: patientQuery
}
type Mutation {
addPost(name: String, title: String, content: String): patientQuery
}
schema {
query: Query
mutation: Mutation
}
`,
resolvers: {
patientQuery: {
find(root, params, context, ast) {
console.log('testing');
return ['title'];
}
}
}
});
但是当我做这样的查询时
{
patient {
find
}
}
我总是得到 null
{
"data": {
"patient": null
}
}
那么,解析patientQuery 类型中的字段的正确方法是什么?
【问题讨论】:
-
乍一看,我怀疑这与您正在返回一个字符串但该字段应返回一个字符串数组的事实有关。尝试返回
return ['title'] -
更改了返回数组的解析函数,但我仍然得到 null
标签: graphql graphql-js apollostack apollo-server