Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relay Connection authorization integration #1752

Closed
swalkinshaw opened this issue Aug 8, 2018 · 3 comments
Closed

Relay Connection authorization integration #1752

swalkinshaw opened this issue Aug 8, 2018 · 3 comments

Comments

@swalkinshaw
Copy link
Collaborator

Visibility and accessibility both have integration with Relay connections here:

if member.respond_to?(:relay_node_type) && (t = member.relay_node_type)
member = t
end

However this doesn't apply to authorization since authorized? is called from field instrumentation and not via call_on_type_class on the schema.

Is this something that should be taken care of automatically? I'd also assume relay_node_type should be the source of authorized? for the connection and edge.

@rmosolgo
Copy link
Owner

rmosolgo commented Aug 8, 2018

I wasn't really sure how to make it work. For example, let's say you have a connection which wraps a AR::Relation of Items. Should it go to Item.authorized? ? That means that .authorized? should be prepared for both an Item and an AR::Relation.

A related feature was added for something like this: #1723

@swalkinshaw
Copy link
Collaborator Author

We've always delegated to node type with implementations like this:

# Edge
def authorized?(edge, ctx)
  node_type.authorized?(edge.node, ctx)
end

# Connection
def authorized?(connection, ctx)
  edge_authorizations = connection.edges.map { |edge| edge_type.authorized?(edge, ctx) }
  Promise.all(edge_authorizations).then(&:all?)
end

@rmosolgo
Copy link
Owner

This is kinda done here:

def authorized?(obj, ctx)
true # Let nodes be filtered out
end
def accessible?(ctx)
node_type.accessible?(ctx)
end
def visible?(ctx)
node_type.visible?(ctx)
end

def authorized?(obj, ctx)
true
end
def accessible?(ctx)
node_type.accessible?(ctx)
end
def visible?(ctx)
node_type.visible?(ctx)
end

It might be improved by ahead-of-time filtering of nodes, as shown above, but right now that filtering is delayed until the node itself is queried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants