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

Commit

Permalink
Fix n problems in README and Gem (#52)
Browse files Browse the repository at this point in the history
* Fix two problems in README

* Update README.md

* Add notice for possible error when upgrading

* Only define Field if using graphql >= 1.8 to avoid a load error
  • Loading branch information
phyrog authored Jun 20, 2018
1 parent 0e2fb3e commit b5961fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
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

0 comments on commit b5961fb

Please sign in to comment.