Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Add this line to your application's Gemfile:

```ruby
gem 'graphql-pundit'
gem 'graphql-pundit', '~> 0.7.0'
```

And then execute:
Expand All @@ -20,6 +20,15 @@ And then execute:
$ bundle
```

### Upgrade Notice

If you're upgrading from an earlier version, make sure to delete your
`bootsnap` cache, to avoid a load error (see
[this issue](https://github.com/ontohub/graphql-pundit/issues/51)).
The cache files are usually located in the `tmp` directory in your
repository and are named `bootsnap-compile-cache` and
`bootsnap-load-path-cache`.

## Usage

### Class based API (`graphql-ruby >= 1.8`)
Expand Down Expand Up @@ -163,7 +172,7 @@ class User < BaseObject
authorize: true,
record: ->(obj, args, ctx) { ctx[:current_user] }
field :password_hash, ... do
authorize policy: ->(obj, args, ctx) { ctx[:current_user] }
authorize record: ->(obj, args, ctx) { ctx[:current_user] }
end

# will use AccountPolicy#email? with the first account as the record (the policy was inferred from the record class)
Expand All @@ -184,7 +193,9 @@ initialize the policy with, but for mutations there is no parent object.
###### `before_scope` and `after_scope`

`before_scope` and `after_scope` can be used to apply Pundit scopes to the
fields. Both options can be combined freely within one field.
fields. Both options can be combined freely within one field. The result of
`before_scope` is passed to the resolver as the "parent object", while the
result of `after_scope` is returned as the result of the field.

```ruby
class User < BaseObject
Expand Down
11 changes: 7 additions & 4 deletions lib/graphql-pundit/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

module GraphQL
module Pundit
# Field class that contains authorization and scope behavior
class Field < GraphQL::Schema::Field
prepend GraphQL::Pundit::Scope
prepend GraphQL::Pundit::Authorization
if defined?(GraphQL::Schema::Field)
# Field class that contains authorization and scope behavior
# This only works with graphql >= 1.8.0
class Field < GraphQL::Schema::Field
prepend GraphQL::Pundit::Scope
prepend GraphQL::Pundit::Authorization
end
end
end
end
2 changes: 1 addition & 1 deletion lib/graphql-pundit/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module GraphQL
module Pundit
VERSION = '0.7.0'
VERSION = '0.7.1'
end
end