I have a very small test set of user, collection and object nodes, only about 30. I use the neo4j-graphql-js package to setup a node graphql server to handle requests.
My graphql queries usually take between 300ms to 900ms. Now, they sometimes take 30 seconds for the initial query and back to 300ms on subsequent fetches.
I recently changed @auth for my object and collection nodes schemas, it now look ups user permissions via relationships. I don't see how this could cause some of my queries to go to 20-30 full seconds.
Here is my schema:
type User {
id: ID! @id(autogenerate: true)
authId: String! @unique
email: String
editCollections: \[Collection!\]!
@relationship(type: "EDIT", direction: OUT)
readCollections: \[Collection!\]!
@relationship(type: "READ", direction: OUT)
editObjects: \[Object!\]!
@relationship(type: "EDIT", direction: OUT)
readObjects: \[Object!\]!
@relationship(type: "READ", direction: OUT)
createdAt: DateTime! @timestamp(operations: \[CREATE\])
updatedAt: DateTime! @timestamp(operations: \[UPDATE\])
}
extend type User @auth(
rules: \[
{
operations: \[UPDATE\],
isAuthenticated: true,
bind: { authId: "$jwt.sub" }
},
{
isAuthenticated: true,
allow: { authId: "$jwt.sub" }
},
{
operations: \[READ\],
isAuthenticated: true,
allow: {
OR: \[
{ editCollections: { editUsers: { authId: "$jwt.sub" } } },
{ editCollections: { readUsers: { authId: "$jwt.sub" } } },
{ readCollections: { editUsers: { authId: "$jwt.sub" } } },
{ readCollections: { readUsers: { authId: "$jwt.sub" } } }
\]
}
}
\]
)
type Collection {
id: ID! @id(autogenerate: true)
name: String!
selfCollection: Boolean!
trashCollection: Boolean!
editUsers: \[User!\]!
@relationship(type: "EDIT", direction: IN)
readUsers: \[User!\]!
@relationship(type: "READ", direction: IN)
containsObjects: \[Object!\]!
@relationship(type: "CONTAINS", direction: OUT, properties: "Contains")
rootsObjects: \[Object!\]!
@relationship(type: "ROOTS", direction: OUT)
createdAt: DateTime! @timestamp(operations: \[CREATE\])
createdBy: String!
updatedAt: DateTime! @timestamp(operations: \[UPDATE\])
updatedBy: String!
}
extend type Collection @auth(rules: [
{
operations: \[READ\],
isAuthenticated: true,
allow: {
OR: \[
{ editUsers: { authId: "$jwt.sub" } },
{ readUsers: { authId: "$jwt.sub" } }
\]
}
}
{
operations: \[CREATE, UPDATE, CONNECT, DISCONNECT, DELETE\]
isAuthenticated: true,
allow: {
editUsers: { authId: "$jwt.sub" }
}
}
])
type Object {
id: ID! @id(autogenerate: true)
name: String!
collections: \[Collection!\]!
@relationship(type: "CONTAINS", direction: IN, properties: "Contains")
rootCollections: \[Collection!\]!
@relationship(type: "ROOTS", direction: IN)
containsObjects: \[Object!\]!
@relationship(type: "CONTAINS", direction: OUT, properties: "Contains")
objectContains: \[Object!\]!
@relationship(type: "CONTAINS", direction: IN, properties: "Contains")
createdAt: DateTime! @timestamp(operations: \[CREATE\])
createdBy: String!
updatedAt: DateTime! @timestamp(operations: \[UPDATE\])
updatedBy: String!
removedAt: DateTime @timestamp(operations: \[CREATE\])
removedBy: String
images: \[Image\]
parentRelation: String
[@cypher](https://community.neo4j.com/t5/user/viewprofilepage/user-id/8343)(
statement: "MATCH (this)<-\[c:CONTAINS\]-(p:Object) RETURN c.relation"
)
childrenIds: \[String!\]!
[@cypher](https://community.neo4j.com/t5/user/viewprofilepage/user-id/8343)(
statement: "MATCH (this)-\[:CONTAINS\*\]->(c:Object) RETURN collect(c.id)"
)
}
extend type Object @auth(rules: [
{
operations: \[READ\],
isAuthenticated: true,
allow: {
OR: \[
{ rootCollections: { editUsers: { authId: "$jwt.sub" } } },
{ rootCollections: { readUsers: { authId: "$jwt.sub" } } }
\]
}
}
{
operations: \[CREATE, UPDATE, CONNECT, DISCONNECT, DELETE\]
isAuthenticated: true,
allow: {
rootCollections: { editUsers: { authId: "$jwt.sub" } }
}
}
])