Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Class based API: parent object passed to policy is instance of the object type class, not an instance of the model class. #53

@haizop

Description

@haizop

When calling authorize, the 'parent object' passed to the policy is not an instance of the relevant model, it is instead an instance of the object type.

# Gemfile
gem 'graphql-pundit', '~> 0.7.1'

...

class Types::BaseObject < GraphQL::Schema::Object
  field_class GraphQL::Pundit::Field
end

...

class AppSchema < GraphQL::Schema
  query Types::Query
end

...

class Types::Query < Types::BaseObject
  field :current_user, Types::User, null: true

  def current_user
    context[:current_user]
  end
end

...

class Types::User < Types::BaseObject
  field :test_pundit, String, null: true do
    authorize ->(obj, args, ctx) {
      binding.pry
      # obj.class => Types::User
      # obj.object.class => User
    }
  end

  # compare with class of obj as passed to resolver.
  field :test, String, null: true, resolve: ->(obj, args, ctx) { 
    binding.pry
    # obj.class => User
  }
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions