Accessing restricted model property returns both data and errors #813
-
So it's the first time for me running into a situation where some properties of a model are protected via an authorization decorator. I also set Query Result: {
"data": {
"share": {
"id": "f9d531d3-94f0-4876-af17-deda34194345",
"members": [
{
"id": "f0d8e1f0-aeb1-11e8-a117-43673ffd376b",
"name": "<name>",
"email": "<email>",
"status": null,
"permissions": null,
"shareID": "f9d531d3-94f0-4876-af17-deda34194345",
"dateJoined": "2021-03-11T18:15:39.595Z"
},
{
"id": "3ba6fab4-f6ad-4916-9f1d-cdcfe522fd8e",
"name": "<name>",
"email": "<email>",
"status": null,
"permissions": null,
"shareID": "f9d531d3-94f0-4876-af17-deda34194345",
"dateJoined": "2021-03-11T18:15:39.598Z"
}
]
}
},
"errors": [
{
"message": "User has insufficient permissions to perform this action!",
"locations": [{ "line": 8, "column": 7 }],
"path": ["share", "members", 0, "status"],
"extensions": {
"code": "FORBIDDEN"
}
},
{
"message": "User has insufficient permissions to perform this action!",
"locations": [{ "line": 9, "column": 7 }],
"path": ["share", "members", 0, "permissions"],
"extensions": {
"code": "FORBIDDEN"
}
},
{
"message": "User has insufficient permissions to perform this action!",
"locations": [{ "line": 8, "column": 7 }],
"path": ["share", "members", 1, "status"],
"extensions": {
"code": "FORBIDDEN"
}
},
{
"message": "User has insufficient permissions to perform this action!",
"locations": [{ "line": 9, "column": 7 }],
"path": ["share", "members", 1, "permissions"],
"extensions": {
"code": "FORBIDDEN"
}
}
],
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yes, that's how GraphQL works. If something bad happens, like Then it continues resolving other fields, because the response is still matching the defined types. So you can have "partial" response and the
That's up to you - I think frontend should never make a query that violates validation or authentication rules. If for some reason this doesn't fits you (leaking permissions info), you can use |
Beta Was this translation helpful? Give feedback.
Yes, that's how GraphQL works.
If something bad happens, like
TypeError
orundefined is not a function
inside the resolver, the errors bubbles up in the types and fields chain (nested properties) until it find a nullable field.Then it continues resolving other fields, because the response is still matching the defined types.
So you can have "partial" response and the
errors
array containing the detailed info.That's up to you - I think frontend should never make a query that violates validation or authentication rules.
Most implementations like Apollo will throw an error if there's some data in
errors
.If for som…