Mel*_*991 7 graphql graphql-js
GraphQL将我的标题和内容属性解析为null,尽管数据肯定是从服务器检索的 - 控制台日志确认它.从graphql只返回_id属性,这是我从查询中得到的内容json { listings: [ { _id: '56e6c94f1cf94a7c0a4e22ba', title: null, content: null } ] }据我所知,一切都设置正确,我还尝试给标题和内容一个GraphQLIDType来排除它所输入的差异.
我有一个graphql查询:
query(`
query findListings {
listings(offset: 1) {
_id,
title,
content
}
}
`).then((json) => {
console.log('json', json.data)
})
Run Code Online (Sandbox Code Playgroud)
我的根查询类型:
const QueryType = new GraphQLObjectType({
name: 'Query',
fields: {
listings: {
name: 'listings',
type: new GraphQLList(ListingType),
args: {
limit: {
type: GraphQLInt
},
offset: {
type: GraphQLInt
}
},
resolve(source, args, info) {
const { fieldASTs } = info
const projection = getProjection(fieldASTs[0])
return ListingModel.find({}, projection).then(listing => {
console.log(listing)
return listing
})
}
}
}
})
Run Code Online (Sandbox Code Playgroud)
和我的"列表类型":
const ListingType = new GraphQLObjectType({
name: 'Listing',
fields: {
_id: {
type: GraphQLID
},
title: {
type: GraphQLString
},
content: {
type: GraphQLString
}
}
})
Run Code Online (Sandbox Code Playgroud)
小智 1
我知道这是旧的,但有类似的问题,当查询列表返回 null 时。
查询数组时,您将得到一个对象 {key: yourArray},因此它应该是:
return ListingModel.find({}, projection).then(listing => {
console.log(listing)
return {listing: listing}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
854 次 |
| 最近记录: |