I've read the documentation, tried a bunch of configurations and looked around for a solution, but am still coming up empty handed to the following challenge.
Schema:
type User {
id: ID! @id
userName: String!
posts: [Post!]! @relationship(type: "WROTE", direction: "OUT")
}
type Post {
id: ID! @id
author: User! @relationship(type: "WROTE", direction: "IN")
body: String!
}
extend type User @authorization(filter:[
{ where: { node: { id: "$jwt.sub" } } }
])
Desired behavior: Every time a user submits a post, that post is automatically connected to the user.
Assumptions: The user must be signed in to submit a post. The graphql request includes a jwt in the headers from the authentication session, which is decoded and injected into the graphql server context. The jwt includes the "sub" field which contains the user's id.
Question: In @neo4j/graphql 4.x, how can i leverage the @authorization or @authentication directives, the '$jwt.sub' data and/or the "connect" command in the auto-generated mutation set to achieve this result?
What i don't want is to have to manually pull the user id string from the jwt.sub and inject that into the variable object on the front end and send that over the wire (this would be cumbersome and potentially prone to mistakes). I want this to happen automatically in the background since the schema knows how the Users and Posts are related and the user's id is always present in the included jwt sent for every graphql request.
Any thoughts?