Hi there!
We are experimenting with enterprise feature ACL in combination with GraphQL endpoint (Docker image: dgraph/dgraph:v20.11.1).
Our setup is:
Types:
type Product {
productID: ID!
name: String @search(by: [term])
reviews: [Review] @hasInverse(field: about)
}
type Customer {
username: String! @id @search(by: [hash, regexp])
reviews: [Review] @hasInverse(field: by)
}
type Review {
id: ID!
about: Product!
by: Customer!
comment: String @search(by: [fulltext])
rating: Int @search
}
Mutations:
mutation {
addProduct(input: [
{ name: "GraphQL on Dgraph"},
{ name: "Dgraph: The GraphQL Database"}
]) {
product {
productID
name
}
}
addCustomer(input: [{ username: "Michael"}]) {
customer {
username
}
}
}
mutation {
addReview(input: [{
by: {username: "Michael"},
about: { productID: "0x5"},
comment: "Fantastic, easy to install, worked great. Best GraphQL server available",
rating: 10}])
{
review {
comment
rating
by { username }
about { name }
}
}
}
Create one user Alice
:
mutation {
addUser(input: [{name: "alice", password: "newpassword"}]) {
user {
name
}
}
}
Create one group dev
:
mutation {
addGroup(input: [{name: "dev"}]) {
group {
name
users {
name
}
}
}
}
Add Alice
to dev
group:
mutation {
updateUser(input: {filter: {name: {eq: "alice"}}, set: {groups: [{name: "dev"}]}}) {
user {
name
groups {
name
}
}
}
}
Set permisions for dev:
mutation {
updateGroup(input: {filter: {name: {eq: "dev"}}, set: {rules: [
{predicate: "Review.comment", permission: 7},
{predicate: "Review.by", permission: 7},
{predicate: "Review.about", permission: 7},
{predicate: "Customer.username", permission: 7},
{predicate: "Product.productID", permission: 7},
{predicate: "Product.reviews", permission: 7},
{predicate: "Review.rating", permission: 7},
]}}) {
group {
name
rules {
permission
predicate
}
}
}
}
Alice does not have permision for Product.name
predicate.
When we execute GraphQL query like this:
query {
queryProduct(filter: { name: {anyofterms: "Database"}}) {
productID
reviews {
rating
}
name
}
}
results are:
{
"data": {
"queryProduct": [
{
"productID": "0x5",
"reviews": [
{
"rating": 10
}
],
"name": null
},
{
"productID": "0x6",
"name": null
}
]
}
}
Alice is not able to search in Product.name
. Why we get listing of all Products?
We have try to reproduce same results in DQL and it looks that “query translator” from GraphQL to DQL is not correct. We got same results with query:
byTypeAndFilter(func: type(Product)) @filter(anyofterms(Product.name,"Database")) {
uid
Product.name
Product.reviews {
Review.rating
}
}
}
but we are expecting results generated from this (Alice has not privilges so no results are returned):
{
byName(func: anyofterms(Product.name,"Database")) {
uid
Product.name
Product.reviews {
Review.rating
}
}
What are we doing wrong? Can be used ACL in conbination with GraphQL?
Thank you,
Roman