lowip
10/17/2017, 4:34 PM# Comment
# - Schema
type Comment @model {
# Generated by server
id: ID! @isUnique
createdAt: DateTime!
updatedAt: DateTime!
# Data
text: String!
# - Relations
parent: Comment @relation(name: "CommentOnComment")
children: [Comment!]! @relation(name: "CommentOnComment")
author: User! @relation(name: "UserOnComment")
post: Post! @relation(name: "PostOnComment")
votes: [CommentVote!]! @relation(name: "CommentOnCommentVote")
}
And the following permission query on Comment.create
(inspired by https://docs-next.graph.cool/guides/auth/authorization-for-a-cms-miesho4goo#editors-can-only-assign-themselves-as-the-document-owner):
query isUser($user_id: ID!, $authorUser_id: ID!) {
SomeUserExists(filter: {
AND: [
{ id: $user_id },
{ id: $authorUser_id }
]
})
}
When running the following query (with the right auth token):
mutation create {
createComment(
text: "Waow, amazing",
authorId: "cj8tal6jg0pxv0192epmhlaha",
postId: "cj8vshelb01x601742ff1c0tt",
) {
id
}
}
I have the following error:
Permission Query is invalid. Could not be executed. Error Message: Error during variable coercion. Violations:\n\nVariable '$authorUser_id' expected value of type 'ID!' but value is undefined. Reason: Expected non-null value, found null. (line 1, column 29):\nquery isUser($user_id: ID!, $authorUser_id: ID!) {\n ^
Am I doing something wrong here?mwickett
10/17/2017, 4:38 PMmwickett
10/17/2017, 4:39 PMlowip
10/17/2017, 4:39 PMmwickett
10/17/2017, 4:44 PM{
SomeUserExists(
filter: {
id: $user_id
comments_some: { id: $node_id }
}
)
}
lowip
10/17/2017, 4:46 PMFor all write operations, all matching permission queries are executed and evaluated before the pending operation
The user doesn't have the comment yet when I'm creating itlowip
10/17/2017, 4:49 PMcomments_some
returns false 😕lowip
10/17/2017, 6:11 PM- operation: Vote.create
authenticated: true
query: ./src/permissions/vote/isUser.graphql
But changing it to:
- operation: Vote.create
authenticated: true
- operation: UserOnVote.connect
authenticated: true
query: ./src/permissions/vote/isUser.graphql
- operation: PostOnVote.connect
authenticated: true
Fixed the issue