Code Monkey home page Code Monkey logo

Comments (2)

rmosolgo avatar rmosolgo commented on June 13, 2024

Hey, thanks for reporting this. Did you find this documented somewhere? I didn't find it in the documentation and I don't see it addressed in the relevant spec (https://github.com/rmosolgo/graphql-ruby/blob/master/spec/graphql/authorization_spec.rb), so I think it was just never dreamed of!

But we could definitely add it. My first thought on a place to add it would be to hook in here:

when "SCALAR", "ENUM"
r = begin
current_type.coerce_result(value, context)

and here:

coerced_value = begin
type.coerce_input(value, context)
rescue StandardError => err
context.schema.handle_or_reraise(context, err)
end

Which go here:

def coerce_result(value, ctx)
warden = ctx.warden
all_values = warden ? warden.enum_values(self) : values.each_value
enum_value = all_values.find { |val| val.value == value }
if enum_value
enum_value.graphql_name
else
raise self::UnresolvedValueError.new(enum: self, value: value, context: ctx)
end
end
def coerce_input(value_name, ctx)
all_values = ctx.warden ? ctx.warden.enum_values(self) : values.each_value
if v = all_values.find { |val| val.graphql_name == value_name }
v.value
elsif v = all_values.find { |val| val.value == value_name }
# this is for matching default values, which are "inputs", but they're
# the Ruby value, not the GraphQL string.
v.value
else
nil
end
end

I think if those two methods (coerce_input and coerce_result) included enum_value.authorized? checks, it would implement this feature.

Feel free to give it a try if you're interested, otherwise I'll keep this open and try to take a crack at it when I find time!

from graphql-ruby.

vitaliiorlov avatar vitaliiorlov commented on June 13, 2024

@rmosolgo thank you for looking into this.

Did you find this documented somewhere? I didn't find it in the documentation...

No, there is no documentation regarding this. I just looked around the source code and found that the enum value also has those methods (visible? and authorized?). So, I have such a case in my project where I would like to have such a feature, but tried to work with that and found out that visible? is working correctly, but authorized? does not. This is a short story about how I created this bug because, in the gem's source code, I've seen such a method and anticipated it should work then.

from graphql-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.