试图从graphQL查询中获取IdType列表。当前使用自省来获取列表,但是建议在进行安全审核后禁用自省。
这是我目前所拥有的,显然不起作用:(
import mongoose from 'mongoose'
import { GQC } from 'graphql-compose';
import { composeWithMongoose } from 'graphql-compose-mongoose';
export const IdTypeSchema = new mongoose.Schema({
idType: {
type: String,
enum: ['ID', 'Passport', 'None']
}
})
const IdType = mongoose.model('IdType', IdTypeSchema)
export const IdTypeTC = composeWithMongoose(IdType, {})
GQC.rootQuery().addFields({
idTypesMany: IdTypeTC.getResolver('findMany')
})
枚举不太可能经常更改。
答案 0 :(得分:0)
我没有解决这个问题-但这是起作用的:D 完全不需要猫鼬...
import { GQC, Resolver } from 'graphql-compose'
import { validateSession } from '../authentication'
import { ID_TYPES } from './constants'
export function _idTypeResolveHandler () {
return ID_TYPES
}
const idTypeResolver = new Resolver({
name: 'getIdTypes',
type: ['String'],
resolve: _idTypeResolveHandler
})
GQC.rootQuery().addFields({
idTypes: idTypeResolver
.wrapResolve(next => resolveParams => {
const { user } = resolveParams.context.state
return next(resolveParams)
})
})