Tag: mongoose graphql

将自定义types的列表传递给GraphQL变体

我的应用程序的目标是让用户能够保存和调用要填写和编辑的表单列表。 一个用户将有多种forms,一个表单将由其自己的几个领域组成。 如果我的types是这样设置的,例如: const FormType = new GraphQLObjectType({ name: 'FormType', fields: { id: { type: GraphQLID }, name: { type: GraphQLString }, email: { type: GraphQLString } } }); const UserType = new GraphQLObjectType({ name: 'UserType', fields: { id: { type: GraphQLID }, email: { type: GraphQLString }, firstName: { type: GraphQLString, default: '' }, […]

GraphQL Mongoose承诺最佳实践

使用GraphiQL,我可以使用以下命令更新用户(1)。 我能够返回实际用户与服务(3)。 更新后有更简单/更紧凑的方式来返回用户吗? (看到创build用户有多容易)。 (1)GraphiQL突变命令变异{updateUser(id:“1”,firstName:“Bob”){firstName}} (2)突变: const mutation = new GraphQLObjectType({ updateUser: { type: UserType, args: { id: { type: new GraphQLNonNull(GraphQLString) }, firstName: { type: GraphQLString }, age: { type: GraphQLInt }, companyId: { type: GraphQLString } }, resolve(parentValue, args){ return UserService.updateUser(args); } }, }) (3)服务: function updateUser(args) { var {id} = args; return […]

灵活的字段input到graphql

我正在使用MongoDB与Graphql描述这里工作很好,但我已经在我的一个项目中使用了mongodb架构如下: var mongoose=require('mongoose'); var Schema=mongoose.Schema({ },{ strict: false }); module.exports=mongoose.model('schema',Schema); 正如所料,我可以添加从客户端发送的任何领域,这是mongoDB(Schemaless)的美丽。但我不能看到它在graphql中的支持,就好像我想添加另一个字段,而无需在schema.GraphQL中定义它的照顾每个领域单独如此是有什么想法吗?

如何检查GraphQL查询中的权限和其他条件?

我如何检查用户是否有权查看或查询某些内容? 我不知道如何做到这一点。 在args ? 那将如何工作? 在resolve() ? 看看用户是否有权限,并以某种方式消除/改变一些参数? 例: 如果用户是“访问者”,他只能看到公共职位,“pipe理员”可以看到一切。 const userRole = 'admin'; // Let's say this could be "admin" or "visitor" const Query = new GraphQLObjectType({ name: 'Query', fields: () => { return { posts: { type: new GraphQLList(Post), args: { id: { type: GraphQLString }, title: { type: GraphQLString }, content: { […]