小编suy*_*esh的帖子

如何在 Graphql 解析器中传递 :current_user

我有查询类型

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)

ruby-on-rails ruby-on-rails-5 graphql graphql-ruby

5
推荐指数
1
解决办法
3134
查看次数

如何在 Rails 强参数中添加默认数据?

假设我想在管理中创建用户时生成并设置用户的默认密码。

我想做这样的事情

 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)

我正在使用巫术进行用户身份验证。我有一种感觉,这是完全错误的方式,但我该怎么做呢?

ruby sorcery ruby-on-rails-4

4
推荐指数
1
解决办法
3436
查看次数