public void BuildMutation(MutationRoot mutationRoot)
        {
            mutationRoot.Field <AutoRegisteringObjectGraphType <RefreshTokenResultModel> >(
                "refreshToken",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "authenticationToken"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "refreshToken"
            }),
                resolve: context =>
            {
                var accountService = _contextAccessor.HttpContext.RequestServices.GetRequiredService <IAccountService>();

                return(accountService.RefreshToken(context.GetArgument <string>("authenticationToken"),
                                                   context.GetArgument <string>("refreshToken")));
            }
                );

            mutationRoot.Field <AutoRegisteringObjectGraphType <LoginResultModel> >(
                "login",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "username"
            }, new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                var accountService = _contextAccessor.HttpContext.RequestServices.GetRequiredService <IAccountService>();

                return(accountService.LoginAsync(new LoginModel
                {
                    UserName = context.GetArgument <string>("username"),
                    Password = context.GetArgument <string>("password")
                }));
            }
                );

            mutationRoot.Field <AutoRegisteringObjectGraphType <LoginResultModel> >(
                "register",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "email"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "username"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                var accountService = _contextAccessor.HttpContext.RequestServices.GetRequiredService <IAccountService>();

                return(accountService.RegisterAsync(new RegisterModel
                {
                    UserName = context.GetArgument <string>("username"),
                    Password = context.GetArgument <string>("password"),
                    Email = context.GetArgument <string>("email")
                }));
            }
                );


            mutationRoot.Field <AutoRegisteringObjectGraphType <UserModel> >(
                "createUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "email"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "fullName"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <StringGraphType> > > {
                Name = "roles"
            }),
                resolve: context =>
            {
                var accountService = _contextAccessor.HttpContext.RequestServices.GetRequiredService <IUserService>();

                return(accountService.CreateUserAsync(new CreateUserModel
                {
                    Roles = context.GetArgument <string[]>("roles"),
                    FullName = context.GetArgument <string>("fullName"),
                    Email = context.GetArgument <string>("email"),
                }));
            }
                ).AuthorizeWith("AdminPolicy");


            mutationRoot.Field <BooleanGraphType>(
                "editUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "fullName"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <StringGraphType> > > {
                Name = "roles"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "email"
            }),
                resolve: context =>
            {
                var accountService = _contextAccessor.HttpContext.RequestServices.GetRequiredService <IUserService>();

                return(accountService.UpdateUserAsync(context.GetArgument <int>("id"), new CreateUserModel
                {
                    Roles = context.GetArgument <string[]>("roles"),
                    FullName = context.GetArgument <string>("fullName"),
                    Email = context.GetArgument <string>("email"),
                }));
            }
                ).AuthorizeWith("AdminPolicy");


            mutationRoot.Field <BooleanGraphType>(
                "deleteUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: context =>
            {
                var accountService = _contextAccessor.HttpContext.RequestServices.GetRequiredService <IUserService>();
                var u = TokenHelpers.GetCurrentUsername(_contextAccessor.HttpContext);
                return(accountService.DeleteUserAsync(context.GetArgument <int>("id"), u));
            }
                ).AuthorizeWith("AdminPolicy");
        }
 public EnumMutationSchema()
 {
     Query    = new UserQuery();
     Mutation = new MutationRoot();
 }