简体   繁体   English

使用 HotChocolate 从 UserManager 获取用户

[英]Getting users from UserManager using HotChocolate

How to get list of users from UserManager from Microsoft.AspNetCore.Identity using [ScopedService]如何使用[ScopedService]Microsoft.AspNetCore.IdentityUserManager获取用户列表

Below is what I already tried:以下是我已经尝试过的:

using System.Linq;
using hostapp.Data;
using hostapp.Models;
using HotChocolate;
using HotChocolate.Data;
using Microsoft.AspNetCore.Identity;

namespace hostapp.GraphQL
{
    public class Query
    {
        // 1.
        [UseDbContext(typeof(DataContext))]
        public IQueryable<AppUser> Users([ScopedService] UserManager<AppUser> userManager)
        {
            return (IQueryable<AppUser>)userManager.Users;
        }
        
        // 2.
        [UseDbContext(typeof(DataContext))]
        public async Task<List<AppUser>> Users([ScopedService] UserManager<AppUser> userManager)
        {
            return await userManager.Users.ToListAsync();
        }

    }
}

Input:输入:

query {
  users {
    emailConfirmed
  }
}

Output: Output:

{
  "errors": [
    {
      "message": "Unexpected Execution Error",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "users"
      ]
    }
  ],
  "data": {
    "users": null
  }
}

You do not need to use [ScopedService] but rather [Service] You really only even need to use [ScopedService] in case of a DBContext in combination with UseDbContext .您不需要使用[ScopedService]而是[Service]在 DBContext 与DBContext结合使用的情况下,您实际上甚至只需要使用[ScopedService] UseDbContext We will fix this confusion in the next version我们将在下一个版本中修复这种混淆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用多个身份用户时,没有 Identity.UserManager 类型的服务 - No service for type Identity.UserManager when using multiple identity users 从UserManager使用可查询的Owin用户,并与另一个实体一起加入 - Use queryable of Owin Users from UserManager and join with another entity 如何从UserManager获取包含其声明的用户列表? - How can I get a list of Users that includes their Claims from a UserManager? 我在使用 UserManager.IsInRoleAsync() 时收到 InvalidOperationException - Im getting InvalidOperationException when using UserManager.IsInRoleAsync() 使用UserManager急切加载 - Eager loading using the UserManager 从服务创建用户管理器 - Create a usermanager from a Service 在ASP .NET MVC应用程序中使用UserManager的Seed方法期间没有创建用户 - No users have been created during Seed method using UserManager in ASP .NET MVC applications 使用 Automapper 10.1.1 和 HotChocolate 11.1 到 map 查询 - Using Automapper 10.1.1 and HotChocolate 11.1 to map queryables 使用投影而不返回 IQueryable,GraphQL HotChocolate - Using projections without returning IQueryable, GraphQL HotChocolate 使用UserManager .Net Core过滤用户角色 - Issue filtering users on role with UserManager .Net Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM