Closed ghost closed 6 years ago
I'm trying also with:
gem 'graphql-guard', github: 'exAspArk/graphql-guard', :branch => 'master'
But if I try with this code:
def self.guard(type, field)
type.introspection? || RULES.dig(type, field)
end
I got this:
Completed 500 Internal Server Error in 158ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `call' for true:TrueClass):
app/controllers/graphql_controller.rb:11:in `execute'
Hey @johnunclesam,
Thanks for opening the issue!
I got this: Completed 500 Internal Server Error in 158ms (ActiveRecord: 0.0ms) NoMethodError (undefined method `call' for true:TrueClass)
We've made a mistake in https://github.com/exAspArk/graphql-guard/pull/6, should be fixed.
Instead of:
def self.guard(type, field)
type.introspection? || RULES.dig(type, field)
end
It should be something like:
def self.guard(type, field)
type.introspection? ? nil : RULES.dig(type, field)
end
I.e. if:
type.introspection? == true
The guard
method will return nil
, so no checks will be performed
https://github.com/exAspArk/graphql-guard/blob/cd1ca47f19d3388911f77360f5786846b2870666/lib/graphql/guard.rb#L29
type.introspection? == false
The gem will perform checks by using RULES
I can get introspection types without problems
If you would like to restrict an access to Schema, you can do something like:
def self.guard(type, field)
if type.introspection?
->(obj, args, ctx) { false } # do not allow getting a schema introspection info
else
RULES.dig(type, field)
end
end
For example, loading GraphiQL will fail with the error:
Please let me know if it works for you.
Ok. Thanks for you answer.
1) with type.introspection? ? nil : RULES.dig(type, field)
I can still fetch the schema; maybe your misprint?
2) the if method works good.
Can it work also with:
def self.guard(type, field)
Rails.env.production? && type.introspection? ? ->(obj, args, ctx) { false } : RULES.dig(type, field)
end
??? Right?
@johnunclesam, this would work for you:
def self.guard(type, field)
return RULES.dig(type, field) unless type.introspection?
Rails.env.production? && ->(obj, args, ctx) { false }
end
or
def self.guard(type, field)
return RULES.dig(type, field) unless type.introspection?
->(obj, args, ctx) { !Rails.env.production? }
end
I can still fetch the schema; maybe your misprint?
Yeah, I was referring to "skip authorization" from the README to fix 500. Feel free to contribute and fix it the example in the README if you'd like :)
Can it work also with
@semenovDL @johnunclesam 👍 Any of these approaches may work
https://github.com/exAspArk/graphql-guard/pull/10 done. You can merge, @exAspArk.
Thanks! Closing the issue
If I don't use this:
I can get introspection types without problems which is not good:
My GraphQLPolicy:
Why is introspection skipping authorization?