Open
Description
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