【发布时间】:2019-10-01 22:45:21
【问题描述】:
我有 nodejs 和 graphql 应用程序。
我的用户架构和解析器使用graphql-compose-mongoose:
import { composeWithMongoose } from 'graphql-compose-mongoose';
const UserTC = composeWithMongoose(User, {
fields: { remove: ['password'] },
});
UserTC.addResolver({
name: 'currentUser',
type: UserTC.getType(),
resolve: currentUserResolver, // return user object...
});
我将解析器添加到我的 UserTC:
UserTC.addResolver({
name: 'login',
args: {
email: { type: 'String!' },
password: { type: 'String!' },
},
type: /// <---- MISSING TYPE HERE
resolve: async ({ args, context }) => {
const { email, password } = args;
const { token, user } = login({ email, password });
return { token, user }
},
});
我需要为这个解析器返回 { token, user }。
我应该定义什么类型?
这个我试过但失败了:
type: { token: 'String', user: UserTC.getType() }
【问题讨论】:
标签: node.js graphql graphql-compose-mongoose graphql-compose