我有查询类型
Types::QueryType = GraphQL::ObjectType.define do
name 'Query'
field :allProjects, function: Resolvers::Projects
end
Run Code Online (Sandbox Code Playgroud)
像这样的解析器
require 'search_object/plugin/graphql'
module Resolvers
class Projects
include SearchObject.module(:graphql)
type !types[Types::ProjectType]
scope { Project.all }
ProjectFilter = GraphQL::InputObjectType.define do
name 'ProjectFilter'
argument :OR, -> { types[ProjectFilter] }
argument :description_contains, types.String
argument :title_contains, types.String
end
option :filter, type: ProjectFilter, with: :apply_filter
option :first, type: types.Int, with: :apply_first
option :skip, type: types.Int, with: :apply_skip
def apply_first(scope, value)
scope.limit(value)
end
def apply_skip(scope, value)
scope.offset(value)
end
def apply_filter(scope, value)
branches = normalize_filters(value).reduce …Run Code Online (Sandbox Code Playgroud) 假设我想在管理中创建用户时生成并设置用户的默认密码。
我想做这样的事情
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password=> @default_generated_password, :password_confirmation => @default_generated_password)
end
Run Code Online (Sandbox Code Playgroud)
我正在使用巫术进行用户身份验证。我有一种感觉,这是完全错误的方式,但我该怎么做呢?