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

Slow performance with queries/mutations when @authorization filter is added when working with an indexed ID #5702

Open
Affie opened this issue Oct 24, 2024 · 0 comments

Comments

@Affie
Copy link

Affie commented Oct 24, 2024

Is your feature request related to a problem? Please describe.
Hi, I'm not sure if it's something I'm doing wrong, a bug or new feature. I'm seeing slow performance when querying/mutating nodes by an indexed id when the @authorization filter is on.

Describe the solution you'd like
Performance similar to without @authorization filter.

  • When authz is not included the query/mutation hits the index and returns a result very quickly.
  • Adding authz the generated cypher goes throught all the nodes to filter out and then only match the ID in the where.
  • Perhaps the filter can be applied to the nodes after the where part. With an option or similar?
  • Or is the generated cypher perhaps a bug?

Describe alternatives you've considered
Manually writing resolvers with cypher queries

Additional context
using neo4j 5.24 and neo4j/graphql v5.26.0
Here is an example of the structure

type Root @authorization(filter: [ {where: {node: {users_SOME: {sub: "$jwt.sub"}}}} ])
{
  id: ID! @unique
  foos: [Foo!]! @relationship(type: "HAS_FOO", direction: OUT)
  users: [User!]! @relationship(type: "HAS_USER", direction: OUT)
}

type User @authorization(filter: [{where: {node: {sub: "$jwt.sub"}}}])
{
  sub: ID! @unique
  root: Root! @relationship(type: "HAS_USER", direction: IN)
}

type Foo @authorization(filter: [ {where: {node: {root: {users_SOME: {sub: "$jwt.sub"}}}}} ])
{
  id: ID! @unique
  root: Root! @relationship(type: "HAS_FOO", direction: IN)
  bars: [Bar!]! @relationship(type: "HAS_BARS", direction: OUT)
}

type Bar @authorization(filter: [ {where: {node: {foo: {root: {users_SOME: {sub: "$jwt.sub"}}}}}} ]) 
{
  id: ID! @unique
  foo: Foo! @relationship(type: "HAS_BARS", direction: IN)
}

Here is an example graphql and cypher query generated by neo4j-graphql.

  bars(where: {id: "1"}) {
    id
  }
MATCH (this:Bar)
CALL {
    WITH this
    MATCH (this)<-[:HAS_BARS]-(this0:Foo)
    OPTIONAL MATCH (this0)<-[:HAS_FOO]-(this1:Root)
    WITH *, count(this1) AS rootCount
    WITH *
    WHERE (rootCount <> 0 AND EXISTS {
        MATCH (this1)-[:HAS_USER]->(this2:User)
        WHERE ($jwt.sub IS NOT NULL AND this2.sub = $jwt.sub)
    })
    RETURN count(this0) = 1 AS var3
}
WITH *
WHERE (this.id = $param1 AND ($isAuthenticated = true AND var3 = true))
RETURN this { .id } AS this
@Affie Affie added the enhancement New feature or request label Oct 24, 2024
@darrellwarde darrellwarde added bug Something isn't working performance and removed enhancement New feature or request bug Something isn't working labels Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants