问题描述
我正在尝试将 account-js 与 apollo-server 集成。在我编写完所有代码后,我看到了所有自动生成的模式变更和查询。但是如果我想创建一个新用户,createuser 解析器返回:
{
"data": {
"createuser": {
"userId": null,"loginResult": null
}
}
}
它在 db 中创建一个用户,但不返回任何内容。我在db上看到了记录。我尝试使用该用户登录,但收到“消息”:“用户未设置密码”。我真的不明白问题出在哪里,因为我关注了 apollo 博客上的文章。
链接:https://www.apollographql.com/blog/email-password-authentication-with-accounts-js-and-apollo-server/
我还想用字符串 id 代替对象 ID 创建用户。 Accounts-js 文档说我应该传递“convertUserIdToMongoObjectId: false”选项。我做到了,但它也不起作用。我真的卡住了。
这是我的设置:
const accountsJsInıtializer = ({ mongoConnection }) => {
const accountsPassword = new AccountsPassword()
const accountsMongo = new Mongo(mongoConnection,{
convertUserIdToMongoObjectId: false,dateProvider: (date) => date ? date.toISOString() : new Date().toISOString()
})
const accountsServer = new AccountsServer(
{
db: accountsMongo,tokenSecret: 'secret-token',},{
password: accountsPassword
}
)
return AccountsModule.forRoot({ accountsServer })
}
const apolloLoader = ({ expressApp,mongoConnection }) => {
const accountsGraphQL = accountsJsInıtializer({ mongoConnection })
const schema = makeExecutableSchema({
typeDefs: mergeTypeDefs([typeDefs,accountsGraphQL.typeDefs]),resolvers: mergeResolvers([accountsGraphQL.resolvers,resolvers]),schemaDirectives: {
...accountsGraphQL.schemaDirectives
}
})
const schemaMiddleware = applyMiddleware(schema)
const apollo = new ApolloServer({
schema: schemaMiddleware,context: accountsGraphQL.context,})
apollo.applyMiddleware({ app: expressApp,path: '/graphql' })
return apollo
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)