exAspArk / graphql-guard

Simple authorization gem for GraphQL :lock:
MIT License
472 stars 36 forks source link

Cancancan documentation #1

Closed bricesanchez closed 7 years ago

bricesanchez commented 7 years ago

Hi!

Thanks for your awesome's work on this gem!

I've followed your CanCanCan documentation but it didn't work until i've added this configuration:

# app/graph/graphql_schema.rb
GraphqlSchema = GraphQL::Schema.define do
  query QueryType
  mutation MutationType

  use GraphQL::Guard.new

  resolve_type -> (obj, args, ctx) {
    type_name = obj.class.name
    Schema.types[type_name]
  }
end

I use graphql-guard (~> 1.0.0) on rails 5.1

Did i missed something?

exAspArk commented 7 years ago

Hey!

it didn't work until i've added this configuration

Were there any errors?

What did you exactly add to fix the problem: use GraphQL::Guard.new or resolve_type? What's the graphql-ruby version do you use?

Thanks

bricesanchez commented 7 years ago

What did you exactly add to fix the problem:

use GraphQL::Guard.new

and i use the latest version of graphql-ruby : 1.6.7

exAspArk commented 7 years ago

@bricesanchez thanks for your reply!

In the Usage section, there are 2 categories:

The first sentence states "Add GraphQL::Guard to your schema":

Schema = GraphQL::Schema.define do
  # ...
  use GraphQL::Guard.new
end

"Pass this object to GraphQL::Guard":

Schema = GraphQL::Schema.define do
  # ...
  use GraphQL::Guard.new(policy_object: GraphqlPolicy)
end

So, in the Integration section I was referring to the same Schema from the Usage section :)

If you find it confusing, feel free to open a Pull Request to update the README. I'll be glad to merge it! 🙌