我正在使用graphql-compose和graphql-compose-mongoose。我有一个mongo集合:
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const PressRelease = new Schema({
date: {
type: Date,
required: true
},
articleLink: {
type: String,
required: true
},
articleTitle: {
type: String,
required: true
}
})
module.exports = mongoose.model('PressRelease', PressRelease, 'PressReleases')
在这里我写我的解析器:
import { composeWithMongoose } from 'graphql-compose-mongoose'
import { schemaComposer } from 'graphql-compose'
import { PressRelease } from 'leaf-schemas'
const PressReleaseTC = composeWithMongoose(PressRelease)
const pressReleasesNewest = PressReleaseTC.addResolver({
name: 'pressReleasesNewest',
type: '[PressRelease]',
resolve: async ({ source, args, context, info }) => {
return PressRelease.find({}).sort({ date: -1 })
}
})
schemaComposer.Query.addFields({
pressReleasesNewest
})
export { PressReleaseTC }
即使我在graphql游乐场中将返回类型指定为数组,也不是数组类型:
我还尝试指定这种类型:
type: [PressReleaseTC]
这也不起作用。 我在做什么错了?