データは確実にサーバーから取得されていますが、GraphQL はタイトルとコンテンツのプロパティを null として解決しています - のコンソール ログはそれを確認します。_id プロパティのみが graphql から返されます。これがクエリから返されるもの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)
})
私のルートクエリタイプ:
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
})
}
}
}
})
そして私の「リストタイプ」:
const ListingType = new GraphQLObjectType({
name: 'Listing',
fields: {
_id: {
type: GraphQLID
},
title: {
type: GraphQLString
},
content: {
type: GraphQLString
}
}
})